Qt::ItemFlag Qt::ItemFlags
include <qnamespace.h>
enum ItemFlag { NoItemFlags = 0, ItemIsSelectable = 1, ItemIsEditable = 2, ItemIsDragEnabled = 4, ItemIsDropEnabled = 8, ItemIsUserCheckable = 16, ItemIsEnabled = 32, ItemIsAutoTristate = 64, #if QT_DEPRECATED_SINCE(5, 6) ItemIsTristate = ItemIsAutoTristate, #endif ItemNeverHasChildren = 128, ItemIsUserTristate = 256 }; Q_DECLARE_FLAGS(ItemFlags, ItemFlag) Q_DECLARE_OPERATORS_FOR_FLAGS(ItemFlags)
This enum descripbes the properties of an item
constant | Value | Description |
---|---|---|
Qt::NoItemFlags | 0 | It does not have any properties set. |
Qt::ItemIsSelectable | 1 | It can be selected. |
Qt::ItemIsEditable | 2 | It can be edited. |
Qt::ItemIsFragEnabled | 4 | It can be dragged. |
Qt::ItemIsDropEnabled | 8 | It can be used as a drop target. |
Qt::ItemIsUserCheckable | 16 | It can be checked or unchecked by the user. |
Qt::ItemIsEnabled | 32 | The user can interact with the item. |
Qt::ItemIsAutoTristate | 64 | The item's state depends on the state of its children. This enables automatic management of the state of parent items in QTreeWidget (checked if all children are checked, unchecked if all children are unchecked, or partially checked if only some children are checked). |
Qt::ItemIsTristate | 64 | expired, use ItemIsAutoTristate. |
Qt::ItemNeverHasChildren | 128 | The item never has child items. This is used for optimization purposes only. |
Qt::ItemIsUserTristate | 256 | The user can cycle through three separate states. This value was added in Qt 5.5. |
Note
- 需要为可检查项目提供一组合适的初始状态,以指示该项目是否已checked。其中模型/视图组件已经自动处理,但需要为 QListWidgetItem、QTableWidgetItem 和 QTreeWidgetItem 的实例显式设置。
Note that checkable items need to be given both a suitable set of flags and an initial state, indicating whether the item is checked or not. This is handled automatically for model/view components, but needs to be explicitly set for instances of QListWidgetItem, QTableWidgetItem, and QTreeWidgetItem.
- 如果索引设置了 Qt::ItemNeverHasChildren 标志,则重新实现 QAbstractItemModel::hasChildren 以对该索引返回 true 是未定义的行为。
Note that it is undefined behavior to reimplement QAbstractItemModel::hasChildren to return true for an index if that index has the Qt::ItemNeverHasChildren flag set.
- ItemFlags是QFlags
的typedef, 它存储 ItemFlag 值的 OR 组合。
The ItemFlags type is a typedef for QFlags
. It stores an OR combination of ItemFlag values.
code
[virtual] Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const [virtual] bool QAbstractItemModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
本文来自博客园,作者:flxx,转载请注明原文链接:https://www.cnblogs.com/faithlocus/p/16484451.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)