CheckDelegate QML Type
带有可开启或关闭的复选指示器的项目委托。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- checkState : enumeration
- nextCheckState : function
(since QtQuick.Controls 2.4 (Qt 5.11))
- tristate : bool
详细说明
CheckDelegate 显示一个可切换为打开(选中)或关闭(取消选中)的项目委托。选中委托通常用于从列表中的一组选项中选择一个或多个选项。对于较小的选项集或需要唯一标识的选项,可考虑使用CheckBox 代替。
CheckDelegate 的 API 继承自ItemDelegate ,而 又继承自AbstractButton 。例如,您可以设置text ,并使用AbstractButton API 对clicks 做出反应。可以使用checked 属性设置校验委托的状态。
除了 "已选中 "和 "未选中 "状态外,还有第三种状态:"部分选中"。可以使用tristate 属性启用部分选中状态。这种状态表示无法确定常规的已选中/未选中状态,通常是因为其他状态影响了选中委托。例如,在树状视图中选择了多个子节点时,这种状态非常有用。
ListView { model: ["Option 1", "Option 2", "Option 3"] delegate: CheckDelegate { text: modelData } }
另请参阅 自定义 CheckDelegate、委托控件和CheckBox 。
属性文档
checkState : enumeration |
nextCheckState : function |
该属性包含一个回调函数,每当用户通过触摸、鼠标或键盘交互式切换选中委托时,该函数就会被调用,以确定下一个选中状态。
默认情况下,普通检查委托在Qt.Unchecked
和Qt.Checked
状态之间循环,三态检查委托在Qt.Unchecked
、Qt.PartiallyChecked
和Qt.Checked
状态之间循环。
nextCheckState
回调函数可以覆盖默认行为。下面的示例实现了一个三态检查委托,该委托可根据外部条件呈现部分检查状态,但当用户交互切换时,它永远不会循环到部分检查状态。
CheckDelegate { tristate: true checkState: allChildrenChecked ? Qt.Checked : anyChildChecked ? Qt.PartiallyChecked : Qt.Unchecked nextCheckState: function() { if (checkState === Qt.Checked) return Qt.Unchecked else return Qt.Checked } }
该属性在 QtQuick.Controls 2.4 (Qt 5.11) 中引入。
tristate : bool |
该属性决定了选中委托是否有三种状态。
在下面的动画中,第一个校验委托是三态的:
默认值为false
,即委托只有两种状态。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.