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 >.