PySide6.QtCore.QItemSelectionModel¶
- class QItemSelectionModel¶
QItemSelectionModel类用于跟踪视图中的选定项。更多…概要¶
属性¶
方法¶
def
__init__()def
currentIndex()def
hasSelection()def
isRowSelected()def
isSelected()def
model()def
selectedRows()def
selection()def
setModel()
虚拟方法¶
插槽¶
def
clearSelection()
信号¶
def
currentChanged()def
modelChanged()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
一个
QItemSelectionModel用于跟踪视图或同一模型的多个视图中选中的项目。它还跟踪视图中当前选中的项目。QItemSelectionModel类是模型/视图类之一,是 Qt 模型/视图框架的一部分。选中的项目使用范围存储。每当您想要修改选中的项目时,请使用
select()并提供QItemSelection,或QModelIndex和SelectionFlag。QItemSelectionModel采用双层方法来管理选择,处理已提交的选定项目和当前选择中的项目。当前选定的项目是当前交互式选择的一部分(例如使用橡皮筋选择或键盘移位选择)。要更新当前选定的项目,请使用
Current和其他任何SelectionFlags的按位或。如果省略Current命令,将创建一个新的当前选择,并将前一个选择添加到整个选择中。所有函数都在两个层上操作;例如,selecteditems()将返回两个层中的项目。- 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 –
QAbstractItemModelparent –
QObject
构建一个选择模型,该模型在指定的项目
model上操作,并使用parent。- clear()¶
清除选择模型。发出
selectionChanged()和currentChanged()。- clearCurrentIndex()¶
清除当前索引。发出
currentChanged()。- clearSelection()¶
清除选择模型中的选择。发出
selectionChanged()。- columnIntersectsSelection(column[, parent=QModelIndex()])¶
- Parameters:
column – 整数
parent –
QModelIndex
- Return type:
布尔
如果在给定的
parent的column中有任何选中的项,则返回true。注意
自 Qt 5.15 起,
parent的默认参数是一个空的模型索引。- currentChanged(current, previous)¶
- Parameters:
current –
QModelIndexprevious –
QModelIndex
每当当前项发生变化时,都会发出此信号。
previous模型项索引被current索引替换为选择的当前项。请注意,当项目模型重置时,此信号将不会发出。
属性
currentIndexᅟ的通知信号。- currentColumnChanged(current, previous)¶
- Parameters:
current –
QModelIndexprevious –
QModelIndex
如果
current项发生变化并且其列与previous当前项的列不同,则会发出此信号。请注意,当项目模型重置时,此信号将不会发出。
- currentIndex()¶
- Return type:
返回当前项的模型项索引,如果没有当前项,则返回无效索引。
另请参阅
属性
currentIndexᅟ的获取器。- currentRowChanged(current, previous)¶
- Parameters:
current –
QModelIndexprevious –
QModelIndex
如果
current项发生变化并且其行与previous当前项的行不同,则会发出此信号。请注意,当项目模型重置时,此信号将不会发出。
- emitSelectionChanged(newSelection, oldSelection)¶
- Parameters:
newSelection –
QItemSelectionoldSelection –
QItemSelection
比较两个选择
newSelection和oldSelection并发出selectionChanged(),包含取消选择和选择的项目。- hasSelection()¶
- Return type:
布尔
如果选择模型包含任何选中的项目,则返回
true,否则返回false。属性
hasSelectionᅟ的获取器。- isColumnSelected(column[, parent=QModelIndex()])¶
- Parameters:
column – 整数
parent –
QModelIndex
- Return type:
布尔
如果给定
parent的column中的所有项目都被选中,则返回true。请注意,此函数通常比在同一列中的所有项目上调用
isSelected()更快,并且不可选择的项目将被忽略。注意
自 Qt 5.15 起,
parent的默认参数是一个空的模型索引。- isRowSelected(row[, parent=QModelIndex()])¶
- Parameters:
row – int
parent –
QModelIndex
- Return type:
布尔
如果给定
parent的row中的所有项目都被选中,则返回true。请注意,此函数通常比在同一行中的所有项目上调用
isSelected()更快,并且不可选择的项目将被忽略。注意
自 Qt 5.15 起,
parent的默认参数是一个空的模型索引。- isSelected(index)¶
- Parameters:
索引 –
QModelIndex- Return type:
布尔
如果给定的模型项
index被选中,则返回true。- model()¶
- Return type:
返回由选择模型操作的项目模型。
属性
modelᅟ的获取器。- modelChanged(model)¶
- Parameters:
模型 –
QAbstractItemModel
当使用
setModel()成功设置model时,会发出此信号。另请参阅
属性
modelᅟ的通知信号。- reset()¶
清除选择模型。不会发出任何信号。
- rowIntersectsSelection(row[, parent=QModelIndex()])¶
- Parameters:
row – int
parent –
QModelIndex
- Return type:
布尔
如果在给定的
parent的row中有任何选中的项目,则返回true。注意
自 Qt 5.15 起,
parent的默认参数是一个空的模型索引。- select(selection, command)¶
- Parameters:
selection –
QItemSelectioncommand –
SelectionFlag的组合
使用指定的
command选择项目selection,并发出selectionChanged()。另请参阅
- select(index, command)
- Parameters:
index –
QModelIndexcommand –
SelectionFlag的组合
使用指定的
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:
返回存储在选择模型中的选择范围。
属性
selectionᅟ的获取器。- selectionChanged(selected, deselected)¶
- Parameters:
selected –
QItemSelectiondeselected –
QItemSelection
每当选择发生变化时,都会发出此信号。选择的变化表示为
deselected项目的项目选择和selected项目的项目选择。请注意,当前索引的变化与选择无关。还要注意,当项目模型重置时,不会发出此信号。
保持选中但更改其索引的项目不包括在
selected和deselected中。因此,如果仅更改选中项目的索引,则可能会发出此信号,且selected和deselected都为空。另请参阅
属性
hasSelectionᅟ的通知信号。- setCurrentIndex(index, command)¶
- Parameters:
index –
QModelIndexcommand –
SelectionFlag的组合
将模型项
index设置为当前项,并发出currentChanged()。当前项用于键盘导航和焦点指示;它独立于任何选定的项,尽管选定的项也可以是当前项。根据指定的
command,index也可以成为当前选择的一部分。另请参阅
- setModel(model)¶
- Parameters:
模型 –
QAbstractItemModel
将模型设置为
model。将会发出modelChanged()信号。另请参阅
属性
modelᅟ的设置器。