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