PySide6.QtCore.QModelIndex¶
- class QModelIndex¶
QModelIndex类用于定位数据模型中的数据。更多…概要¶
方法¶
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()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
此类用作从
QAbstractItemModel派生的项目模型的索引。项目视图、委托和选择模型使用此索引来定位模型中的项目。新的
QModelIndex对象由模型使用createIndex()函数创建。可以使用QModelIndex构造函数构建一个无效的模型索引。无效索引通常用作父索引,当引用模型中的顶级项目时。模型索引指的是模型中的项目,并包含指定它们在模型中位置所需的所有信息。每个索引位于给定的行和列中,并且可能有一个父索引;使用
row()、column()和parent()来获取这些信息。模型中的每个顶级项目由一个没有父索引的模型索引表示——在这种情况下,parent()将返回一个无效的模型索引,相当于使用QModelIndex()构造函数的零参数形式构造的索引。要获取引用模型中现有项的模型索引,请使用所需的行和列值以及父项的模型索引调用
index()。当引用模型中的顶级项时,提供QModelIndex()作为父索引。model()函数返回索引引用的模型作为QAbstractItemModel。child() 函数用于检查模型中索引下的项目。sibling()函数允许你遍历模型中与索引处于同一级别的项目。注意
模型索引应立即使用然后丢弃。你不应依赖索引在调用改变模型结构或删除项目的模型函数后仍然有效。如果你需要长期保持一个模型索引,请使用
QPersistentModelIndex。- __init__()¶
创建一个新的空模型索引。这种类型的模型索引用于指示模型中的位置无效。
- column()¶
- Return type:
整数
返回此模型索引所引用的列。
- constInternalPointer()¶
- Return type:
void
返回一个
const void*指针,模型使用该指针将索引与内部数据结构关联。另请参阅
- data([role=Qt.DisplayRole])¶
- Parameters:
角色 – int
- Return type:
对象
返回由索引引用的项目的给定
role的数据,如果此模型索引是invalid,则返回默认构造的QVariant。返回由索引引用的项目的标志。
- internalId()¶
- Return type:
quintptr
返回一个
quintptr,模型使用它来将索引与内部数据结构关联。另请参阅
- internalPointer()¶
- Return type:
void
返回一个
void*指针,模型使用该指针将索引与内部数据结构关联。另请参阅
- isValid()¶
- Return type:
布尔
如果此模型索引有效,则返回
true;否则返回false。有效的索引属于一个模型,并且具有非负的行号和列号。
- model()¶
- Return type:
返回指向包含此索引所引用项的模型的指针。
返回一个指向模型的常量指针,因为对模型的非常量函数的调用可能会使模型索引无效,并可能导致应用程序崩溃。
- multiData(roleDataSpan)¶
- Parameters:
roleDataSpan –
QModelRoleDataSpan
为索引所引用的项目填充给定的
roleDataSpan。- __ne__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
如果
lhs模型索引不指向与rhs模型索引相同的位置,则返回true;否则返回false。- __ne__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- __lt__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
如果
lhs模型索引小于rhs模型索引,则返回true;否则返回false。小于计算对开发者来说并不直接有用——不同父索引的比较方式未定义。此运算符仅存在以便该类可以与
QMap一起使用。- __lt__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- __le__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
- __le__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- __eq__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
如果
lhs模型索引与rhs模型索引指向相同的位置,则返回true;否则返回false。内部数据指针、行、列和模型值用于与另一个模型索引进行比较。
- __eq__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- __gt__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
- __gt__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- __ge__(rhs)¶
- Parameters:
rhs –
QModelIndex- Return type:
布尔
- __ge__(rhs)
- Parameters:
rhs –
QPersistentModelIndex- Return type:
布尔
- parent()¶
- Return type:
返回模型索引的父级,如果没有父级则返回
QModelIndex()。- row()¶
- Return type:
整数
返回此模型索引所引用的行。
- sibling(row, column)¶
- Parameters:
row – int
column – 整数
- Return type:
返回位于
row和column的兄弟节点。如果该位置没有兄弟节点,则返回一个无效的QModelIndex。- siblingAtColumn(column)¶
- Parameters:
列 – int
- Return type:
返回当前行在
column处的兄弟节点。如果该位置没有兄弟节点,则返回一个无效的QModelIndex。另请参阅
- siblingAtRow(row)¶
- Parameters:
行 – 整数
- Return type:
返回当前列的
row处的兄弟节点。如果该位置没有兄弟节点,则返回一个无效的QModelIndex。