QModelIndexclass is used to locate data in a data model. 更多 …
def
__eq__
(other)
def
__lt__
(other)
def
__ne__
(other)
def
child
(row, column)
def
column
()
def
data
([role=Qt.DisplayRole])
def
flags
()
def
internalId
()
def
internalPointer
()
def
isValid
()
def
model
()
def
parent
()
def
row
()
def
sibling
(row, column)
def
siblingAtColumn
(column)
def
siblingAtRow
(row)
此类被用作项模型的索引,派生自
QAbstractItemModel. The index is used by item views, delegates, and selection models to locate an item in the model.New
QModelIndexobjects are created by the model using thecreateIndex()function. An invalid model index can be constructed with theQModelIndexconstructor. 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(),和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,parent()will return an invalid model index, equivalent to an index constructed with the zero argument form of theQModelIndex()构造函数。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.
model()function returns the model that the index references as aQAbstractItemModel。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.注意
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.
QModelIndex
¶
QModelIndex(QModelIndex)
- param QModelIndex
Creates a new empty model index. This type of model index is used to indicate that the position in the model is invalid.
PySide2.QtCore.QModelIndex.
child
(
row
,
column
)
¶
row
–
int
column
–
int
注意
此函数被弃用。
使用
index()
代替。
Returns the child of the model index that is stored in the given
row
and
column
.
注意
This function does not work for an invalid model index which is often used as the root index.
PySide2.QtCore.QModelIndex.
column
(
)
¶
int
Returns the column this model index refers to.
PySide2.QtCore.QModelIndex.
data
(
[
role=Qt.DisplayRole
]
)
¶
role
–
int
object
返回数据为给定
role
for the item referred to by the index.
PySide2.QtCore.QModelIndex.
flags
(
)
¶
ItemFlags
Returns the flags for the item referred to by the index.
PySide2.QtCore.QModelIndex.
internalId
(
)
¶
quintptr
返回
quintptr
used by the model to associate the index with the internal data structure.
另请参阅
PySide2.QtCore.QModelIndex.
internalPointer
(
)
¶
void
返回
void
*
pointer used by the model to associate the index with the internal data structure.
另请参阅
PySide2.QtCore.QModelIndex.
isValid
(
)
¶
bool
返回
true
若此模型索引有效;否则返回
false
.
A valid index belongs to a model, and has non-negative row and column numbers.
PySide2.QtCore.QModelIndex.
model
(
)
¶
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.
PySide2.QtCore.QModelIndex.
__ne__
(
other
)
¶
other
–
QModelIndex
bool
返回
true
if this model index does not refer to the same location as the
other
model index; otherwise returns
false
.
PySide2.QtCore.QModelIndex.
__lt__
(
other
)
¶
other
–
QModelIndex
bool
PySide2.QtCore.QModelIndex.
__eq__
(
other
)
¶
other
–
QModelIndex
bool
返回
true
if this model index refers to the same location as the
other
model index; otherwise returns
false
.
The internal data pointer, row, column, and model values are used when comparing with another model index.
PySide2.QtCore.QModelIndex.
parent
(
)
¶
Returns the parent of the model index, or
QModelIndex()
if it has no parent.
PySide2.QtCore.QModelIndex.
row
(
)
¶
int
Returns the row this model index refers to.
PySide2.QtCore.QModelIndex.
sibling
(
row
,
column
)
¶
row
–
int
column
–
int
Returns the sibling at
row
and
column
. If there is no sibling at this position, an invalid
QModelIndex
被返回。
PySide2.QtCore.QModelIndex.
siblingAtColumn
(
column
)
¶
column
–
int
Returns the sibling at
column
for the current row. If there is no sibling at this position, an invalid
QModelIndex
被返回。
另请参阅
PySide2.QtCore.QModelIndex.
siblingAtRow
(
row
)
¶
row
–
int
Returns the sibling at
row
for the current column. If there is no sibling at this position, an invalid
QModelIndex
被返回。