The QModelIndex class is used to locate data in a data model. 更多...
| 头: | #include <QModelIndex> |
| QModelIndex () | |
| QModelIndex (const QModelIndex & other ) | |
| ~QModelIndex () | |
| QModelIndex | child (int row , int column ) const |
| int | column () const |
| QVariant | data (int role = Qt::DisplayRole) const |
| Qt::ItemFlags | flags () const |
| qint64 | 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 |
| 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 () function is used to examine items held under the index in the model. The sibling () 函数允许在如索引的同一级别遍历模型项。
注意: 模型索引应立即使用,然后丢弃。不应依赖要保持有效的索引,在调用改变模型结构 (或删除项) 的模型函数后。若需要随时间推移保持模型索引,使用 QPersistentModelIndex .
另请参阅 模型/视图编程 , QPersistentModelIndex ,和 QAbstractItemModel .
创建新的空模型索引。这种类型的模型索引用于指示模型的位置无效。
另请参阅 isValid () 和 QAbstractItemModel .
Creates a new model index that is a copy of the other 模型索引。
Destroys the model index.
Returns the child of the model index that is stored in the given row and column .
注意: This function does not work for an invalid model index which is often used as the root index.
返回此模型索引所引用的列。
返回数据为给定 role 对于索引所引用的项。
返回由索引所引用的项标志。
该函数在 Qt 4.2 引入。
返回
qint64
用于模型,以将索引关联内部数据结构。
另请参阅 QAbstractItemModel::createIndex ().
返回
void
*
指针用于模型,以将索引关联内部数据结构。
另请参阅 QAbstractItemModel::createIndex ().
Returns true if this model index is valid; otherwise returns false.
有效索引属于模型,且拥有非负行号和列号。
另请参阅 model (), row (),和 column ().
返回包含此索引所引用项的模型指针。
返回模型 const 指针,因为调用模型的非 const 函数会使模型索引无效,并可能会使应用程序崩溃。
返回模型索引的父级,或 QModelIndex () 若它没有父级。
另请参阅 child (), sibling (),和 model ().
返回此模型索引所引用的行。
返回同级在 row and column 。若此位置没有同级,无效 QModelIndex 被返回。
Returns true if this model index does not refer to the same location as the other model index; otherwise returns false.
Returns true if this model index is smaller than the other model index; otherwise returns false.
该函数在 Qt 4.1 引入。
Returns true if this model index refers to the same location as the other model index; otherwise returns false.
All values in the model index are used when comparing with another model index.
同义词 QList < QModelIndex >.