Qt 改变宽度不会改变';不生效
我有以下切换开关: 由该QML代码开发Qt 改变宽度不会改变';不生效,qt,qml,Qt,Qml,我有以下切换开关: 由该QML代码开发 Row { id: myToggle anchors.horizontalCenter: parent.horizontalCenter width: 270 height: 25 StyledLabel { id: myToggleLabel text:
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
现在可以调整开关宽度:
切勿水平锚定在
行中
或垂直锚定在列中