我的页面中有 3 个单选按钮,QML 桌面应用程序。一旦我检查了一个 - 我希望所有其他都未选中。
我尝试使用 CheckableGroup
使用我在帮助中找到的代码:
CheckableGroup { id: group }
Row {
id: row
spacing: platformStyle.paddingMedium
RadioButton {
id: button1
text: "1"
platformExclusiveGroup: group
}
RadioButton {
id: button2
text: "2"
platformExclusiveGroup: group
}
RadioButton {
id: button3
text: "3"
platformExclusiveGroup: group
checked: true
}
}
但我收到错误“platformExclusiveGroup 不是有效的属性名称”我尝试了另一种解决方案
RadioButton {
id: rbtnDecimal1
width: 130
onClicked: {
if (checked) {
rbtnHexadecimal1.checked=false;
rbtnString1.checked=false;
}
}
text: "Decimal Data";
anchors.left: rbtnHexadecimal1.right
}
当一个按钮被选中时,所有其他按钮都未选中,但其他按钮保持选中状态,直到我将鼠标移到它们上 - 它们变得未选中。知道如何实现吗?
最佳答案
您需要指定 ExclusiveGroup
对于RadioButton
s。
Row {
id: row
ExclusiveGroup { id: group }
RadioButton {
id: button1
text: "1"
exclusiveGroup: group
}
RadioButton {
id: button2
text: "2"
exclusiveGroup: group
}
RadioButton {
id: button3
text: "3"
exclusiveGroup: group
checked: true
}
}
关于qt - QML 桌面中的单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13450829/