Reputation: 884
I am having a group of buttons in a Column
and i have set autoExclusive : true
. Now only one button can be checked as expected. But, how to disable the checked state if i click on the button which is already checked? Following is the code:
Column {
id: column
Button {
checked: true
text: qsTr("button 1")
autoExclusive : true
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
Button {
checked: true
text: qsTr("button 2")
autoExclusive : true
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
Button {
checked: true
text: qsTr("button 3")
autoExclusive : true
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
}
Upvotes: 2
Views: 6698
Reputation: 884
There is a way to do this by using ButtonGroup :
Column {
id: column
Button {
checked: true
text: qsTr("button 1")
ButtonGroup.group: btnGrp //assign buttongroup
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
Button {
checked: true
text: qsTr("button 2")
ButtonGroup.group: btnGrp //assign buttongroup
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
Button {
checked: true
text: qsTr("button 3")
ButtonGroup.group: btnGrp //assign buttongroup
checkable : true
background: Rectangle {
color:checked ? "red" : "white"
}
}
}
ButtonGroup {
id:btnGroup
}
Now loop through btnGrp.buttons
and can check the button state to true or false and also can get checked button by accessing btnGrp.checkedButton
.
Upvotes: 3