QT - QML 9.4.2实例 RadioButton & exclusiveGroup

qt quick 9.4.2实例

import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

import QtQuick.Window 2.2


Window {

    title: qsTr("选择你喜欢的手机操作系统")
    visible: true
    width: 640
    height: 600
    color: "lightblue"

    Rectangle{  //弹出对话框样式
        id:resultHolder
        color: "black"
        width: 400
        height: 120
        anchors.centerIn: parent  //anchors锚布局
        visible: false
        z:2
        opacity: 0.8   //透明度
        border.width: 23
        border.color: "red"
        Text {
            id: result
            anchors.centerIn: parent
            font.pointSize: 40
            color: "blue"
            font.bold:true
        }
    }

    ExclusiveGroup{    //头文件
        id:mos
    }

    Component{
        id:radioStyle
        RadioButtonStyle{
            indicator: Rectangle{     //显示器
                implicitWidth: 64   //潜在宽度,椭圆边框宽度
                implicitHeight: 64  //椭圆边框高度
                radius:12    //直角圆半径
                border.color: control.hovered ?"darkblue":"gray"
                border.width: 2
                Rectangle{
                    id:visrectangle
                    anchors.fill: parent
                    visible: control.checked  //
                    color: "black"
                    radius: 10
                    anchors.margins: 6
                }
            }
            label: Text {
                color: control.activeFocus?"blue":"black"
                text:control.text
            }
        }
    }

    Text {
        id: notation
        text: "please select the best mobile os:"
        //font.bold:true
        //font.pixelSize: 12
        anchors.top:parent.top
        anchors.topMargin: 32
        anchors.left: parent.left
        anchors.leftMargin: 16
    }

    RadioButton{     //android
        id:android
        text: "Android"
        exclusiveGroup:mos
        anchors.top: notation.bottom
        anchors.topMargin: 8
        anchors.left: notation.left  //符号 注释 记号
        anchors.leftMargin: 40

        checked: true   //如果控件被选中 属性为真
        //focus:true  //焦点属性

        activeFocusOnPress: true
        style:radioStyle
        onClicked: resultHolder.visible = false
    }

    RadioButton{     //ios
        id:ios
        text: "ios"
        exclusiveGroup:mos
        anchors.top: android.bottom
        anchors.topMargin: 8
        anchors.left: android.left  //符号 注释 记号
        //checked: true
        //focus:true
        activeFocusOnPress: true
        style:radioStyle
        onClicked: resultHolder.visible = false  //
    }

    RadioButton{     //wp
        id:wp
        text: "wp"
        exclusiveGroup:mos
        anchors.top: ios.bottom
        anchors.topMargin: 8
        anchors.left: ios.left  //符号 注释 记号
        //checked: true
       // focus:true
        activeFocusOnPress: true
        style:radioStyle
        onClicked: resultHolder.visible=false
    }

    RadioButton{     //firefox
        id:firefox
        text: "firefox"
        exclusiveGroup:mos
        anchors.top: wp.bottom
        anchors.topMargin: 8
        anchors.left: wp.left  //符号 注释 记号
        //checked: true
       // focus:true
        activeFocusOnPress: true
        style:radioStyle
        onClicked: resultHolder.visible=false
    }

    RadioButton{     //wp
        id:sailfish
        text: "sailfish OS"
        exclusiveGroup:mos
        anchors.top: firefox.bottom
        anchors.topMargin: 8
        anchors.left: firefox.left  //符号 注释 记号
       // checked: true
       // focus:true
        activeFocusOnPress: true
        style:radioStyle
        onClicked: resultHolder.visible=false
    }

    Button{
        id:confirm
        text: "confirm"
        anchors.top:sailfish.bottom
        anchors.topMargin: 16
        anchors.left: notation.left
        onClicked: {
            result.text = mos.current.text
            resultHolder.visible = true
        }

    }

}

 

 - - END - - 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值