QItemSelection 类
QItemSelection 类管理模型中选中项的信息。 更多...
头文件 | #include <QItemSelection> |
CMake | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake | QT += core |
继承 | QList |
公有函数
QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight) | |
QItemSelection() | |
bool | contains(const QModelIndex &index) const |
QModelIndexList | indexes() const |
void | merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command) |
void | select(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
静态公有成员
void | split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result) |
详细说明
A QItemSelection describes the items in a model that have been selected by the user. A QItemSelection is basically a list of selection ranges, see QItemSelectionRange. It provides functions for creating and manipulating selections, and selecting a range of items from a model.
The QItemSelection class is one of the Model/View Classes and is part of Qt's model/view framework.
An item selection can be constructed and initialized to contain a range of items from an existing model. The following example constructs a selection that contains a range of items from the given model
, beginning at the topLeft
, and ending at the bottomRight
.
QItemSelection *selection = new QItemSelection(topLeft, bottomRight);
An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way
QItemSelection *selection = new QItemSelection(); ... selection->select(topLeft, bottomRight);
QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each item in the selection. Generally, an instance of this class will contain a list of non-overlapping selection ranges.
Use merge() to merge one item selection into another without making overlapping ranges. Use split() to split one selection range into smaller ranges based on a another selection range.
另请参阅 模型/视图编程 和 QItemSelectionModel.
成员函数文档
QItemSelection::QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight)
使用指定的 topLeft 索引指定的顶部左侧模型项和 bottomRight 索引指定的底部右侧模型项来构建一个范围从顶部左侧到底部右侧的项目选择。
[noexcept default]
QItemSelection::QItemSelection()
构造一个空的选择。
bool QItemSelection::contains(const QModelIndex &index) const
如果选择包含指定的 index,则返回 true
;否则返回 false
。
QModelIndexList QItemSelection::indexes() const
返回对应于所选项目的模型索引列表。
void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
使用给定的 command 将 other 选择与该 QItemSelection 合并。此方法保证没有重叠的范围。
注意,只支持 QItemSelectionModel::Select、QItemSelectionModel::Deselect 和 QItemSelectionModel::Toggle。
另请参阅 split().
void QItemSelection::select(const QModelIndex &topLeft, const QModelIndex &bottomRight)
将指定为 topLeft 索引的顶部左侧模型项到指定为 bottomRight 索引的底部右侧模型项的范围中的项目添加到列表中。
注意: topLeft 和 bottomRight 必须具有相同的父项。
[static]
void QItemSelection::split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result)
使用选择范围 other 来拆分选择范围 range。从 range 中删除所有在 other 中的项目,并将结果放入 result 中。这可以与集合的 subtract 操作的语义进行比较。
另请参阅 merge().
© 2024 Qt 公司有限公司。此处包含的文档贡献是各自所有者的版权。此处提供的文档是根据自由软件基金会出版的 GNU 自由文档许可证版本 1.3 的条款许可的。Qt 及其标志是芬兰的 Qt 公司及其它国家/地区的商标。所有其他商标均为其各自所有者的财产。