Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 改变宽度不会改变';不生效_Qt_Qml - Fatal编程技术网

Qt 改变宽度不会改变';不生效

Qt 改变宽度不会改变';不生效,qt,qml,Qt,Qml,我有以下切换开关: 由该QML代码开发 Row { id: myToggle anchors.horizontalCenter: parent.horizontalCenter width: 270 height: 25 StyledLabel { id: myToggleLabel text:

我有以下切换开关:

由该QML代码开发

        Row {
            id: myToggle
            anchors.horizontalCenter: parent.horizontalCenter
            width: 270
            height: 25

            StyledLabel {
                id: myToggleLabel
                text: qsTr("Toggle")
                width: parent.width - myToggleSwitch.width
                anchors.verticalCenter: parent.verticalCenter
            }

            Switch {
                id: myToggleSwitch
                height: parent.height
                implicitWidth: parent.width * 0.25 // changing 0.25 to 0.5
                                                   // or 0.75 or ...
                                                   // doesn't have any effect
                // Also replacing "implicitWidth" with "width" doesn't help!

                anchors.horizontalCenter: parent.horizontalCenter
                checked: true
                onCheckedChanged: { console.log("checked: ", checked) }
            }
        }
我打算更改
标签
占用了多少行宽,以及
开关
本身占用了多少行宽


我将代码中的
0.25
值更改为
0.5
0.75
或。。。但它没有效果。有人知道为什么吗?

设置锚定会干扰设置宽度

将ID为的
开关
的这一行从
ID:myToggleSwitch
上删除,解决了以下问题:

anchors.horizontalCenter: parent.horizontalCenter
现在可以调整开关宽度:


切勿水平锚定在
行中
或垂直锚定在
列中