The QModelIndex class is used to locate data in a data model. 更多...
| 头: | #include <QModelIndex> |
| qmake: | QT += core |
| QModelIndex () | |
| int | column () const |
| QVariant | data (int role = Qt::DisplayRole) const |
| Qt::ItemFlags | flags () const |
| quintptr | internalId () const |
| void * | internalPointer () const |
| bool | isValid () const |
| const QAbstractItemModel * | model () const |
| QModelIndex | parent () const |
| int | row () const |
| QModelIndex | sibling (int row , int column ) const |
| QModelIndex | siblingAtColumn (int column ) const |
| QModelIndex | siblingAtRow (int row ) const |
| bool | operator!= (const QModelIndex & other ) const |
| bool | operator< (const QModelIndex & other ) const |
| bool | operator== (const QModelIndex & other ) const |
| typedef | QModelIndexList |
The QModelIndex class is used to locate data in a data model.
此类用作项模型的索引,派生自 QAbstractItemModel 。用于项视图、委托及选定模型的索引,能定位模型项。
New QModelIndex objects are created by the model using the QAbstractItemModel::createIndex () 函数。 无效 model index can be constructed with the QModelIndex constructor. Invalid indexes are often used as parent indexes when referring to top-level items in a model.
模型索引引用模型中的项,且包含指定它们在这些模型中位置要求的所有信息。各索引位于给定行和列,且可能拥有父级索引;使用 row (), column (),和 parent () 能获得这种信息。模型中的各顶级项都是由不拥有父级索引的模型索引所表示的 - 在此情况下, parent () will return an invalid model index, equivalent to an index constructed with the zero argument form of the QModelIndex () 构造函数。
要获得引用模型中现有项的模型索引,调用 QAbstractItemModel::index () with the required row and column values, and the model index of the parent. When referring to top-level items in a model, supply QModelIndex () as the parent index.
The model () 函数返回索引所引用的模型如 QAbstractItemModel 。child() 函数用于审查由模型索引所保持的项。 sibling () 函数允许在如索引的同一级别遍历模型项。
注意: 模型索引应立即使用,然后丢弃。不应依赖要保持有效的索引,在调用改变模型结构 (或删除项) 的模型函数后。若需要随时间推移保持模型索引,使用 QPersistentModelIndex .
另请参阅 模型/视图编程 , QPersistentModelIndex ,和 QAbstractItemModel .
创建新的空模型索引。这种类型的模型索引用于指示模型的位置无效。
另请参阅 isValid () 和 QAbstractItemModel .
返回此模型索引所引用的列。
返回数据为给定 role 对于索引所引用的项。
返回由索引所引用的项标志。
该函数在 Qt 4.2 引入。
返回
quintptr
用于模型,以将索引关联内部数据结构。
另请参阅 QAbstractItemModel::createIndex ().
返回
void
*
指针用于模型,以将索引关联内部数据结构。
另请参阅 QAbstractItemModel::createIndex ().
返回
true
若此模型索引有效;否则返回
false
.
有效索引属于模型,且拥有非负行号和列号。
另请参阅 model (), row (),和 column ().
返回包含此索引所引用项的模型指针。
返回模型 const 指针,因为调用模型的非 const 函数会使模型索引无效,并可能会使应用程序崩溃。
返回模型索引的父级,或 QModelIndex () 若它没有父级。
返回此模型索引所引用的行。
返回同级在 row and column 。若此位置没有同级,无效 QModelIndex 被返回。
另请参阅 parent (), siblingAtColumn (),和 siblingAtRow ().
返回同级在 column 对于当前行。若此位置没有同级,无效 QModelIndex 被返回。
该函数在 Qt 5.11 引入。
另请参阅 sibling () 和 siblingAtRow ().
返回同级在 row 对于当前列。若此位置没有同级,无效 QModelIndex 被返回。
该函数在 Qt 5.11 引入。
另请参阅 sibling () 和 siblingAtColumn ().
返回
true
若此模型索引未引用同一位置如
other
模型索引;否则返回
false
.
返回
true
若此模型索引 <
other
模型索引;否则返回
false
.
< 计算对开发者并非直接有用 - 没有定义采用不同父级的索引比较方式。此运算符才存在,以便类可以用于 QMap .
该函数在 Qt 4.1 引入。
返回
true
若此模型索引引用同一位置如
other
模型索引;否则返回
false
.
使用内部数据指针、行、列及模型值,当比较另一模型索引时。
同义词 QList < QModelIndex >.