use*_*297 5 desktop qt radio-button qml
我的页面中有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
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误"platformExclusiveGroup不是一个有效的属性名称"我尝试了另一种解决方案
RadioButton{
id:rbtnDecimal1;
width: 130;
onClicked:{
if(checked){
rbtnHexadecimal1.checked=false;
rbtnString1.checked=false;
}
}
text: "Decimal Data";
anchors.left:rbtnHexadecimal1.right
}
Run Code Online (Sandbox Code Playgroud)
当一个按钮被选中时,所有其他按钮都被取消选中,但是其他按钮会被检查,直到我将鼠标移到它们上面 - 它们变为未被检查.
任何想法如何实现它?
小智 5
您需要ExclusiveGroup为RadioButtons指定一个。
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
}
}
Run Code Online (Sandbox Code Playgroud)
QML 桌面组件中的 RadioButton 不支持您的第一种方法,但您可以尝试以下解决方法:
property int currentIndex: 1
onCurrentIndexChanged: {
button1.checked = currentIndex == 0
button2.checked = currentIndex == 1
button3.checked = currentIndex == 2
}
Row {
RadioButton {
id: button1
text: "1"
onClicked:{
currentIndex = 0
}
}
RadioButton {
id: button2
text: "2"
onClicked:{
currentIndex = 1
}
}
RadioButton {
id: button3
text: "3"
onClicked:{
currentIndex = 2
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4818 次 |
| 最近记录: |