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

  1. 需要为可检查项目提供一组合适的初始状态,以指示该项目是否已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.

  1. 如果索引设置了 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.

  1. 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
posted @   flxx  阅读(1046)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示