PySide6.QtCore.QItemSelectionModel

class QItemSelectionModel

QItemSelectionModel 类用于跟踪视图中的选定项。更多

PySide6.QtCore.QItemSelectionModel 的继承图

概要

属性

方法

虚拟方法

插槽

信号

注意

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

详细描述

一个QItemSelectionModel用于跟踪视图或同一模型的多个视图中选中的项目。它还跟踪视图中当前选中的项目。

QItemSelectionModel 类是模型/视图类之一,是 Qt 模型/视图框架的一部分。

选中的项目使用范围存储。每当您想要修改选中的项目时,请使用select()并提供QItemSelection,或QModelIndexSelectionFlag

QItemSelectionModel 采用双层方法来管理选择,处理已提交的选定项目和当前选择中的项目。当前选定的项目是当前交互式选择的一部分(例如使用橡皮筋选择或键盘移位选择)。

要更新当前选定的项目,请使用Current和其他任何SelectionFlags的按位或。如果省略Current命令,将创建一个新的当前选择,并将前一个选择添加到整个选择中。所有函数都在两个层上操作;例如,selecteditems()将返回两个层中的项目。

注意

自5.5版本起,modelhasSelectioncurrentIndex是元对象属性。

另请参阅

QAbstractItemModel

class SelectionFlag

(继承自 enum.Flag) 此枚举描述了选择模型的更新方式。

常量

描述

QItemSelectionModel.NoUpdate

不会进行任何选择。

QItemSelectionModel.Clear

完整的选择将被清除。

QItemSelectionModel.Select

所有指定的索引将被选中。

QItemSelectionModel.Deselect

所有指定的索引将被取消选择。

QItemSelectionModel.Toggle

所有指定的索引将根据其当前状态被选中或取消选中。

QItemSelectionModel.Current

当前选择将被更新。

QItemSelectionModel.Rows

所有索引将扩展为跨行。

QItemSelectionModel.Columns

所有索引将扩展为跨列。

QItemSelectionModel.SelectCurrent

Select 和 Current 的组合,为了方便提供。

QItemSelectionModel.ToggleCurrent

切换和当前的组合,为了方便提供。

QItemSelectionModel.ClearAndSelect

Clear 和 Select 的组合,为了方便而提供。

注意

当使用from __feature__ import true_property时,属性可以直接使用,否则通过访问器函数使用。

property currentIndexᅟ: QModelIndex
Access functions:
property hasSelectionᅟ: bool
Access functions:
property modelᅟ: QAbstractItemModel
Access functions:
property selectedIndexesᅟ: list of QModelIndex
Access functions:
property selectionᅟ: QItemSelection
Access functions:
__init__([model=None])
Parameters:

模型QAbstractItemModel

构建一个在指定项目model上操作的选择模型。

__init__(model, parent)
Parameters:

构建一个选择模型,该模型在指定的项目model上操作,并使用parent

clear()

清除选择模型。发出 selectionChanged()currentChanged()

clearCurrentIndex()

清除当前索引。发出 currentChanged()

clearSelection()

清除选择模型中的选择。发出 selectionChanged()

columnIntersectsSelection(column[, parent=QModelIndex()])
Parameters:
Return type:

布尔

如果在给定的parentcolumn中有任何选中的项,则返回true

注意

自 Qt 5.15 起,parent 的默认参数是一个空的模型索引。

currentChanged(current, previous)
Parameters:

每当当前项发生变化时,都会发出此信号。previous 模型项索引被 current 索引替换为选择的当前项。

请注意,当项目模型重置时,此信号将不会发出。

属性 currentIndexᅟ 的通知信号。

currentColumnChanged(current, previous)
Parameters:

如果current项发生变化并且其列与previous当前项的列不同,则会发出此信号。

请注意,当项目模型重置时,此信号将不会发出。

currentIndex()
Return type:

QModelIndex

返回当前项的模型项索引,如果没有当前项,则返回无效索引。

另请参阅

setCurrentIndex()

属性 currentIndexᅟ 的获取器。

currentRowChanged(current, previous)
Parameters:

如果current项发生变化并且其行与previous当前项的行不同,则会发出此信号。

请注意,当项目模型重置时,此信号将不会发出。

emitSelectionChanged(newSelection, oldSelection)
Parameters:

比较两个选择 newSelectionoldSelection 并发出 selectionChanged(),包含取消选择和选择的项目。

hasSelection()
Return type:

布尔

如果选择模型包含任何选中的项目,则返回 true,否则返回 false

属性 hasSelectionᅟ 的获取器。

isColumnSelected(column[, parent=QModelIndex()])
Parameters:
Return type:

布尔

如果给定parentcolumn中的所有项目都被选中,则返回true

请注意,此函数通常比在同一列中的所有项目上调用isSelected()更快,并且不可选择的项目将被忽略。

注意

自 Qt 5.15 起,parent 的默认参数是一个空的模型索引。

isRowSelected(row[, parent=QModelIndex()])
Parameters:
Return type:

布尔

如果给定parentrow中的所有项目都被选中,则返回true

请注意,此函数通常比在同一行中的所有项目上调用isSelected()更快,并且不可选择的项目将被忽略。

注意

自 Qt 5.15 起,parent 的默认参数是一个空的模型索引。

isSelected(index)
Parameters:

索引QModelIndex

Return type:

布尔

如果给定的模型项 index 被选中,则返回 true

model()
Return type:

QAbstractItemModel

返回由选择模型操作的项目模型。

属性 modelᅟ 的获取器。

modelChanged(model)
Parameters:

模型QAbstractItemModel

当使用setModel()成功设置model时,会发出此信号。

另请参阅

model() setModel()

属性 modelᅟ 的通知信号。

reset()

清除选择模型。不会发出任何信号。

rowIntersectsSelection(row[, parent=QModelIndex()])
Parameters:
Return type:

布尔

如果在给定的parentrow中有任何选中的项目,则返回true

注意

自 Qt 5.15 起,parent 的默认参数是一个空的模型索引。

select(selection, command)
Parameters:

使用指定的 command 选择项目 selection,并发出 selectionChanged()

另请参阅

SelectionFlag

select(index, command)
Parameters:

使用指定的command选择模型项index,并发出selectionChanged()

另请参阅

SelectionFlags

selectedColumns([row=0])
Parameters:

– 整数

Return type:

QModelIndex 的列表

返回给定row中所有行都被选择的列的索引。

selectedIndexes()
Return type:

QModelIndex 的列表

返回所有选中的模型项索引的列表。该列表不包含重复项,且未排序。

属性 selectedIndexesᅟ 的获取器。

selectedRows([column=0])
Parameters:

– int

Return type:

QModelIndex 的列表

返回给定column中所有列被选中的行的索引。

selection()
Return type:

QItemSelection

返回存储在选择模型中的选择范围。

属性 selectionᅟ 的获取器。

selectionChanged(selected, deselected)
Parameters:

每当选择发生变化时,都会发出此信号。选择的变化表示为deselected项目的项目选择和selected项目的项目选择。

请注意,当前索引的变化与选择无关。还要注意,当项目模型重置时,不会发出此信号。

保持选中但更改其索引的项目不包括在selecteddeselected中。因此,如果仅更改选中项目的索引,则可能会发出此信号,且selecteddeselected都为空。

另请参阅

select() currentChanged()

属性 hasSelectionᅟ 的通知信号。

setCurrentIndex(index, command)
Parameters:

将模型项 index 设置为当前项,并发出 currentChanged()。当前项用于键盘导航和焦点指示;它独立于任何选定的项,尽管选定的项也可以是当前项。

根据指定的commandindex也可以成为当前选择的一部分。

另请参阅

currentIndex() select()

setModel(model)
Parameters:

模型QAbstractItemModel

将模型设置为model。将会发出modelChanged()信号。

另请参阅

model() modelChanged()

属性 modelᅟ 的设置器。