Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QModelIndex Class

TheQModelIndex class is used to locate data in a data model.More...

Header:#include <QModelIndex>

Public Functions

QModelIndex()
QModelIndex(const QModelIndex & other)
~QModelIndex()
QModelIndexchild(int row, int column) const
intcolumn() const
QVariantdata(int role = Qt::DisplayRole) const
Qt::ItemFlagsflags() const
qint64internalId() const
void *internalPointer() const
boolisValid() const
const QAbstractItemModel *model() const
QModelIndexparent() const
introw() const
QModelIndexsibling(int row, int column) const
booloperator!=(const QModelIndex & other) const
booloperator<(const QModelIndex & other) const
booloperator==(const QModelIndex & other) const

Related Non-Members

Detailed Description

TheQModelIndex class is used to locate data in a data model.

This class is used as an index into item models derived fromQAbstractItemModel. The index is used by item views, delegates, and selection models to locate an item in the model.

NewQModelIndex objects are created by the model using theQAbstractItemModel::createIndex() function. Aninvalid model index can be constructed with theQModelIndex constructor. Invalid indexes are often used as parent indexes when referring to top-level items in a model.

Model indexes refer to items in models, and contain all the information required to specify their locations in those models. Each index is located in a given row and column, and may have a parent index; userow(),column(), andparent() to obtain this information. Each top-level item in a model is represented by a model index that does not have a parent index - in this case,parent() will return an invalid model index, equivalent to an index constructed with the zero argument form of theQModelIndex() constructor.

To obtain a model index that refers to an existing item in a model, callQAbstractItemModel::index() with the required row and column values, and the model index of the parent. When referring to top-level items in a model, supplyQModelIndex() as the parent index.

Themodel() function returns the model that the index references as aQAbstractItemModel. Thechild() function is used to examine items held under the index in the model. Thesibling() function allows you to traverse items in the model on the same level as the index.

Note:Model indexes should be used immediately and then discarded. You should not rely on indexes to remain valid after calling model functions that change the structure of the model or delete items. If you need to keep a model index over time use aQPersistentModelIndex.

See alsoModel/View Programming,QPersistentModelIndex, andQAbstractItemModel.

Member Function Documentation

QModelIndex::QModelIndex()

Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.

See alsoisValid() andQAbstractItemModel.

QModelIndex::QModelIndex(constQModelIndex & other)

Creates a new model index that is a copy of theother model index.

QModelIndex::~QModelIndex()

Destroys the model index.

QModelIndex QModelIndex::child(int row,int column) const

Returns the child of the model index that is stored in the givenrow andcolumn.

Note:This function does not work for an invalid model index which is often used as the root index.

See alsoparent() andsibling().

int QModelIndex::column() const

Returns the column this model index refers to.

QVariant QModelIndex::data(int role = Qt::DisplayRole) const

Returns the data for the givenrole for the item referred to by the index.

Qt::ItemFlags QModelIndex::flags() const

Returns the flags for the item referred to by the index.

This function was introduced in Qt 4.2.

qint64 QModelIndex::internalId() const

Returns aqint64 used by the model to associate the index with the internal data structure.

See alsoQAbstractItemModel::createIndex().

void * QModelIndex::internalPointer() const

Returns avoid* pointer used by the model to associate the index with the internal data structure.

See alsoQAbstractItemModel::createIndex().

bool QModelIndex::isValid() const

Returns true if this model index is valid; otherwise returns false.

A valid index belongs to a model, and has non-negative row and column numbers.

See alsomodel(),row(), andcolumn().

constQAbstractItemModel * QModelIndex::model() const

Returns a pointer to the model containing the item that this index refers to.

A const pointer to the model is returned because calls to non-const functions of the model might invalidate the model index and possibly crash your application.

QModelIndex QModelIndex::parent() const

Returns the parent of the model index, orQModelIndex() if it has no parent.

See alsochild(),sibling(), andmodel().

int QModelIndex::row() const

Returns the row this model index refers to.

QModelIndex QModelIndex::sibling(int row,int column) const

Returns the sibling atrow andcolumn. If there is no sibling at this position, an invalidQModelIndex is returned.

See alsoparent() andchild().

bool QModelIndex::operator!=(constQModelIndex & other) const

Returns true if this model index does not refer to the same location as theother model index; otherwise returns false.

bool QModelIndex::operator<(constQModelIndex & other) const

Returns true if this model index is smaller than theother model index; otherwise returns false.

This function was introduced in Qt 4.1.

bool QModelIndex::operator==(constQModelIndex & other) const

Returns true if this model index refers to the same location as theother model index; otherwise returns false.

All values in the model index are used when comparing with another model index.

Related Non-Members

typedefQModelIndexList

Synonym forQList<QModelIndex>.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp