导入 | import QtQuick.Controls 2.1 |
---|---|
继承 | AbstractButton |
Properties
- checkState : enumeration
- nextCheckState : function
- tristate : bool
细节描述
列表中使用复选框,可以使用 CheckDelegate。
可以使用 non-exclusive 的ButtonGroup来管理分级复选框组。
下面的示例说明了如何将子复选框的组合复选状态绑定到父复选框的复选状态:
Column {
ButtonGroup {
id: childGroup
exclusive: false
checkState: parentBox.checkState
}
CheckBox {
id: parentBox
text: qsTr("Parent")
checkState: childGroup.checkState
}
CheckBox {
checked: true
text: qsTr("Child 1")
leftPadding: indicator.width
ButtonGroup.group: childGroup
}
CheckBox {
text: qsTr("Child 2")
leftPadding: indicator.width
ButtonGroup.group: childGroup
}
}
属性
checkState : enumeration
此属性保存复选框的复选状态。
Constant | Description |
---|---|
Qt.Unchecked | 复选框未选中 |
Qt.PartiallyChecked | 复选框部分被选中。此状态仅在启用trstate时使用 |
Qt.Checked | 复选框选中 |
nextCheckState : function
此属性包含一个回调函数,当用户通过触摸、鼠标或键盘交互切换复选框时,调用该函数来确定下一个复选框状态。
nextCheckState回调函数可以覆盖默认行为。
下面的示例实现了一个三状态复选框,它可以根据外部条件显示部分选中状态,但在用户交互切换时永远不会循环到部分选中状态。
CheckBox {
tristate: true
checkState: allChildrenChecked ? Qt.Checked :
anyChildChecked ? Qt.PartiallyChecked : Qt.Unchecked
nextCheckState: function() {
if (checkState === Qt.Checked)
return Qt.Unchecked
else
return Qt.Checked
}
}
tristate : bool
此属性保存复选框是否为三状态复选框。
默认值是false,也就是说,复选框只有两个状态。