- 要实现的效果:
(1) 多个单选框只能有一个被选中,选中某个时,其他的单选框自动取消选中.
(2) 不管何时需要保证有一个单选框被选中.
CustomCheckbox {
id: chineseCheck
text: qsTr("Chinese")
anchors.left: optionClass.right
anchors.top: parent.top
anchors.topMargin: 40
anchors.leftMargin: 50
checked: true
checkable: false
checkedColor: "#068dfc"
autoExclusive: true
onCheckedChanged: {
if (checked == true)
{
checkable = false;
englishCheck.checked = false;
englishCheck.checkable = true
}
}
}
CustomCheckbox {
id: englishCheck
text: qsTr("English")
anchors.left: optionClass.right
anchors.top: parent.top
anchors.topMargin: 40
anchors.leftMargin: 300
checked: false
checkedColor: "#068dfc"
autoExclusive: true
onCheckedChanged: {
if (checked == true)
{
checkable = false;
chineseCheck.checked = false;
chineseCheck.checkable = true
}
}
}
- 效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/66ad2ee092e3d654189a682b41a867a0.gif#pic_center)