Table Of Contents

Previous topic

QPersistentModelIndex

Next topic

QDataStream

QModelIndex

Inheritance diagram of QModelIndex

Synopsis

Functions

Detailed Description

The PySide.QtCore.QModelIndex class is used to locate data in a data model.

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

New PySide.QtCore.QModelIndex objects are created by the model using the QAbstractItemModel.createIndex() function. An invalid model index can be constructed with the PySide.QtCore.QModelIndex 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; use PySide.QtCore.QModelIndex.row() , PySide.QtCore.QModelIndex.column() , and PySide.QtCore.QModelIndex.parent() 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, PySide.QtCore.QModelIndex.parent() will return an invalid model index, equivalent to an index constructed with the zero argument form of the PySide.QtCore.QModelIndex.QModelIndex() constructor.

To obtain a model index that refers to an existing item in a model, call 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 PySide.QtCore.QModelIndex.QModelIndex() as the parent index.

The PySide.QtCore.QModelIndex.model() function returns the model that the index references as a PySide.QtCore.QAbstractItemModel . The PySide.QtCore.QModelIndex.child() function is used to examine items held under the index in the model. The PySide.QtCore.QModelIndex.sibling() 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 a PySide.QtCore.QPersistentModelIndex .

class PySide.QtCore.QModelIndex
class PySide.QtCore.QModelIndex(other)
Parameters:otherPySide.QtCore.QModelIndex

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

Creates a new model index that is a copy of the other model index.

PySide.QtCore.QModelIndex.child(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
Return type:

PySide.QtCore.QModelIndex

Returns the child of the model index that is stored in the given row and column .

Note

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

PySide.QtCore.QModelIndex.column()
Return type:PySide.QtCore.int

Returns the column this model index refers to.

PySide.QtCore.QModelIndex.data([role=Qt.DisplayRole])
Parameters:rolePySide.QtCore.int
Return type:object

Returns the data for the given role for the item referred to by the index.

PySide.QtCore.QModelIndex.flags()
Return type:PySide.QtCore.Qt.ItemFlags

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

PySide.QtCore.QModelIndex.internalId()
Return type:PySide.QtCore.qint64

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

PySide.QtCore.QModelIndex.internalPointer()
Return type:void

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

PySide.QtCore.QModelIndex.isValid()
Return type:PySide.QtCore.bool

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.

PySide.QtCore.QModelIndex.model()
Return type:PySide.QtCore.QAbstractItemModel

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.

PySide.QtCore.QModelIndex.__ne__(other)
Parameters:otherPySide.QtCore.QModelIndex
Return type:PySide.QtCore.bool

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

PySide.QtCore.QModelIndex.__lt__(other)
Parameters:otherPySide.QtCore.QModelIndex
Return type:PySide.QtCore.bool

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

PySide.QtCore.QModelIndex.__eq__(other)
Parameters:otherPySide.QtCore.QModelIndex
Return type:PySide.QtCore.bool

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.

PySide.QtCore.QModelIndex.parent()
Return type:PySide.QtCore.QModelIndex

Returns the parent of the model index, or PySide.QtCore.QModelIndex.QModelIndex() if it has no parent.

PySide.QtCore.QModelIndex.row()
Return type:PySide.QtCore.int

Returns the row this model index refers to.

PySide.QtCore.QModelIndex.sibling(row, column)
Parameters:
  • rowPySide.QtCore.int
  • columnPySide.QtCore.int
Return type:

PySide.QtCore.QModelIndex

Returns the sibling at row and column . If there is no sibling at this position, an invalid PySide.QtCore.QModelIndex is returned.