QModelIndex Class
The QModelIndex class is used to locate data in a data model. More…
| Header | #include <QModelIndex> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QModelIndex() | |
| int | row() const |
| int | column() const |
| quintptr | internalId() const |
| void * | internalPointer() const |
| const void * | constInternalPointer() const |
| QModelIndex | parent() const |
| QModelIndex | sibling(int row, int column) const |
| QModelIndex | siblingAtColumn(int column) const |
| QModelIndex | siblingAtRow(int row) const |
| QVariant | data(int role = Qt::DisplayRole) const |
| Qt::ItemFlags | flags() const |
| const QAbstractItemModel * | model() const |
| bool | isValid() const |
Detailed Description
A model index refers to an item of a QAbstractItemModel by its row, its column and its parent. Models create indexes with QAbstractItemModel::createIndex(); views and delegates use them to read and change data. An index is only valid until the model's structure changes; use QPersistentModelIndex to keep one.
const QModelIndex index = model->index(2, 0);
const QString text = index.data().toString();
See also QAbstractItemModel and QPersistentModelIndex.
Differences from Qt
There is no multiData() and no QModelRoleDataSpan.
Member Function Documentation
QModelIndex::QModelIndex()
Constructs an invalid index, which refers to the root of a model.
int QModelIndex::column() const
Returns the column of the index, or -1 if it is invalid.
const void * QModelIndex::constInternalPointer() const
Returns the pointer the model stored in the index, as a pointer to const.
This function was introduced in 6.0.
QVariant QModelIndex::data(int role = Qt::DisplayRole) const
Returns the data of the item for role, or an invalid QVariant.
Qt::ItemFlags QModelIndex::flags() const
Returns the flags of the item.
quintptr QModelIndex::internalId() const
Returns the integer the model stored in the index.
See also internalPointer().
void * QModelIndex::internalPointer() const
Returns the pointer the model stored in the index.
See also internalId().
bool QModelIndex::isValid() const
Returns true if the index refers to an item; otherwise returns false.
const QAbstractItemModel * QModelIndex::model() const
Returns the model that the index belongs to, or nullptr for an invalid index.
QModelIndex QModelIndex::parent() const
Returns the parent of the item, or an invalid index for a top-level item or an invalid index.
int QModelIndex::row() const
Returns the row of the index, or -1 if it is invalid.
QModelIndex QModelIndex::sibling(int row, int column) const
Returns the index at row and column under the same parent, or an invalid index.
QModelIndex QModelIndex::siblingAtColumn(int column) const
Returns the index in column of the same row.
This function was introduced in 5.11.
QModelIndex QModelIndex::siblingAtRow(int row) const
Returns the index in row of the same column.
This function was introduced in 5.11.