- class QModelIndex¶
The
QModelIndex
class is used to locate data in a data model. More…Synopsis¶
Methods¶
def
__init__()
def
column()
def
data()
def
flags()
def
internalId()
def
isValid()
def
model()
def
multiData()
def
__ne__()
def
__lt__()
def
__le__()
def
__eq__()
def
__gt__()
def
__ge__()
def
parent()
def
row()
def
sibling()
def
siblingAtRow()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
This class is used as an index into item models derived from
QAbstractItemModel
. The index is used by item views, delegates, and selection models to locate an item in the model.New
QModelIndex
objects are created by the model using thecreateIndex()
function. An invalid 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; use
row()
,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, call
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.The
model()
function returns the model that the index references as aQAbstractItemModel
. The child() 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 a
QPersistentModelIndex
.See also
- __init__()¶
Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.
See also
- column()¶
- Return type:
int
Returns the column this model index refers to.
- constInternalPointer()¶
- Return type:
void
Returns a
const void
*
pointer used by the model to associate the index with the internal data structure.See also
- data([role=Qt.DisplayRole])¶
- Parameters:
role – int
- Return type:
object
Returns the data for the given
role
for the item referred to by the index, or a default-constructedQVariant
if this model index isinvalid
.Returns the flags for the item referred to by the index.
- internalId()¶
- Return type:
quintptr
Returns a
quintptr
used by the model to associate the index with the internal data structure.See also
- internalPointer()¶
- Return type:
void
Returns a
void
*
pointer used by the model to associate the index with the internal data structure.See also
- isValid()¶
- Return type:
bool
Returns
true
if this model index is valid; otherwise returnsfalse
.A valid index belongs to a model, and has non-negative row and column numbers.
- model()¶
- Return type:
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.
- multiData(roleDataSpan)¶
- Parameters:
roleDataSpan –
QModelRoleDataSpan
Populates the given
roleDataSpan
for the item referred to by the index.- __ne__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
Returns
true
iflhs
model index does not refer to the same location as therhs
model index; otherwise returnsfalse
.- __ne__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- __lt__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
Returns
true
iflhs
model index is smaller than therhs
model index; otherwise returnsfalse
.The less than calculation is not directly useful to developers - the way that indexes with different parents compare is not defined. This operator only exists so that the class can be used with
QMap
.- __lt__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- __le__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
- __le__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- __eq__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
Returns
true
iflhs
model index refers to the same location as therhs
model index; otherwise returnsfalse
.The internal data pointer, row, column, and model values are used when comparing with another model index.
- __eq__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- __gt__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
- __gt__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- __ge__(rhs)¶
- Parameters:
rhs –
QModelIndex
- Return type:
bool
- __ge__(rhs)
- Parameters:
rhs –
QPersistentModelIndex
- Return type:
bool
- parent()¶
- Return type:
Returns the parent of the model index, or
QModelIndex()
if it has no parent.- row()¶
- Return type:
int
Returns the row this model index refers to.
- sibling(row, column)¶
- Parameters:
row – int
column – int
- Return type:
Returns the sibling at
row
andcolumn
. If there is no sibling at this position, an invalidQModelIndex
is returned.See also
- siblingAtColumn(column)¶
- Parameters:
column – int
- Return type:
Returns the sibling at
column
for the current row. If there is no sibling at this position, an invalidQModelIndex
is returned.See also
- siblingAtRow(row)¶
- Parameters:
row – int
- Return type:
Returns the sibling at
row
for the current column. If there is no sibling at this position, an invalidQModelIndex
is returned.See also