PySide6.QtCore.QPersistentModelIndex

class QPersistentModelIndex

QPersistentModelIndex 类用于在数据模型中定位数据。更多

概要

方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

一个QPersistentModelIndex是一个可以被应用程序存储的模型索引,稍后用于访问模型中的信息。与QModelIndex类不同,存储QPersistentModelIndex是安全的,因为模型将确保只要模型可以访问,对项目的引用将继续有效。

在使用持久模型索引之前,检查它们是否有效是一个好习惯。

注意

你不能将QStandardItemModel的QPersistentModelIndex存储在模型的任何一个项目中。

__init__()
__init__(index)
Parameters:

索引QModelIndex

创建一个新的QPersistentModelIndex,它是模型index的副本。

__init__(other)
Parameters:

其他QPersistentModelIndex

创建一个新的QPersistentModelIndex,它是other持久模型索引的副本。

column()
Return type:

整数

返回此持久模型索引所引用的列。

constInternalPointer()
Return type:

void

data([role=Qt.DisplayRole])
Parameters:

角色 – int

Return type:

对象

返回由索引引用的项的给定role的数据,如果此持久模型索引是invalid,则返回默认构造的QVariant

另请参阅

ItemDataRole setData()

flags()
Return type:

ItemFlag的组合

返回由索引引用的项目的标志。

internalId()
Return type:

quintptr

internalPointer()
Return type:

void

isValid()
Return type:

布尔

如果此持久模型索引有效,则返回true;否则返回false

有效的索引属于一个模型,并且具有非负的行号和列号。

另请参阅

model() row() column()

model()
Return type:

QAbstractItemModel

返回索引所属的模型。

multiData(roleDataSpan)
Parameters:

roleDataSpanQModelRoleDataSpan

为索引所引用的项目填充给定的roleDataSpan

另请参阅

ItemDataRole setData()

__ne__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

如果 lhs 持久模型索引不指向与 rhs 模型索引相同的位置,则返回 true;否则返回 false

__ne__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

如果 lhs 持久模型索引不等于 rhs 持久模型索引,则返回 true;否则返回 false

__lt__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

__lt__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

如果 lhs 持久模型索引小于 rhs 持久模型索引,则返回 true;否则返回 false

在比较另一个持久模型索引时,使用持久模型索引中的内部数据指针、行、列和模型值。

__le__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

__le__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

__eq__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

如果 lhs 持久模型索引与 rhs 模型索引引用相同的位置,则返回 true;否则返回 false

在与其他模型索引进行比较时,使用持久模型索引中的内部数据指针、行、列和模型值。

__eq__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

如果 lhs 持久模型索引等于 rhs 持久模型索引,则返回 true;否则返回 false

在持久模型索引中,内部数据指针、行、列和模型值用于与另一个持久模型索引进行比较。

__gt__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

__gt__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

__ge__(rhs)
Parameters:

rhsQModelIndex

Return type:

布尔

__ge__(rhs)
Parameters:

rhsQPersistentModelIndex

Return type:

布尔

parent()
Return type:

QModelIndex

返回此持久索引的父级QModelIndex,如果没有父级,则返回无效的QModelIndex

另请参阅

sibling() model()

row()
Return type:

整数

返回此持久模型索引所引用的行。

sibling(row, column)
Parameters:
  • row – int

  • column – 整数

Return type:

QModelIndex

返回位于rowcolumn的兄弟节点,如果该位置没有兄弟节点,则返回无效的QModelIndex

另请参阅

parent()

swap(other)
Parameters:

其他QPersistentModelIndex

将此持久模型索引与other交换。此函数非常快速且永远不会失败。