内容表

上一话题

QItemSelection

下一话题

QItemSelectionRange

QItemSelectionModel

QItemSelectionModel class keeps track of a view’s selected items. 更多

Inheritance diagram of PySide2.QtCore.QItemSelectionModel

概要

函数

虚函数

信号

详细描述

A QItemSelectionModel keeps track of the selected items in a view, or in several views onto the same model. It also keeps track of the currently selected item in a view.

QItemSelectionModel class is one of the 模型/视图类 and is part of Qt’s 模型/视图框架 .

选中项使用范围存储。每当想要修改选中项时,使用 select() and provide either a QItemSelection ,或 QModelIndex SelectionFlag .

QItemSelectionModel takes a two layer approach to selection management, dealing with both selected items that have been committed and items that are part of the current selection. The current selected items are part of the current interactive selection (for example with rubber-band selection or keyboard-shift selections).

要更新目前的选中项,使用按位 OR 的 Current 和任何其它 SelectionFlags 。若省略 Current 命令,将创建新的当前选定,并将之前的一个添加到整个选定。所有函数都在 2 层上运转;例如, selecteditems() 将从 2 层返回项。

注意

从 5.5 起, model , hasSelection ,和 currentIndex 是元对象特性。

class QItemSelectionModel ( [ model=None ] )

QItemSelectionModel(model, parent)

param parent

QObject

param model

QAbstractItemModel

Constructs a selection model that operates on the specified item model .

Constructs a selection model that operates on the specified item model with parent .

PySide2.QtCore.QItemSelectionModel. SelectionFlag

此枚举描述将更新选定模型的方式。

常量

描述

QItemSelectionModel.NoUpdate

No selection will be made.

QItemSelectionModel.Clear

The complete selection will be cleared.

QItemSelectionModel.Select

所有指定索引将被选中。

QItemSelectionModel.Deselect

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

QItemSelectionModel.Toggle

All specified indexes will be selected or deselected depending on their current state.

QItemSelectionModel.Current

当前选定将被更新。

QItemSelectionModel.Rows

将扩展所有索引以跨行。

QItemSelectionModel.Columns

将扩展所有索引以跨列。

QItemSelectionModel.SelectCurrent

A combination of Select and Current, provided for convenience.

QItemSelectionModel.ToggleCurrent

A combination of Toggle and Current, provided for convenience.

QItemSelectionModel.ClearAndSelect

A combination of Clear and Select, provided for convenience.

PySide2.QtCore.QItemSelectionModel. clear ( )

清零选定模型。发射 selectionChanged() and currentChanged() .

PySide2.QtCore.QItemSelectionModel. clearCurrentIndex ( )

清零当前索引。发射 currentChanged() .

PySide2.QtCore.QItemSelectionModel. clearSelection ( )

Clears the selection in the selection model. Emits selectionChanged() .

PySide2.QtCore.QItemSelectionModel. columnIntersectsSelection ( column [ , parent=QModelIndex() ] )
参数
返回类型

bool

返回 true 若有选中任何项在 column 采用给定 parent .

注意

从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。

PySide2.QtCore.QItemSelectionModel. currentChanged ( current , 上一 )
参数
PySide2.QtCore.QItemSelectionModel. currentColumnChanged ( current , 上一 )
参数
PySide2.QtCore.QItemSelectionModel. currentIndex ( )
返回类型

QModelIndex

Returns the model item index for the current item, or an invalid index if there is no current item.

另请参阅

setCurrentIndex()

PySide2.QtCore.QItemSelectionModel. currentRowChanged ( current , 上一 )
参数
PySide2.QtCore.QItemSelectionModel. emitSelectionChanged ( newSelection , oldSelection )
参数

比较 2 选定 newSelection and oldSelection 并发射 selectionChanged() with the deselected and selected items.

PySide2.QtCore.QItemSelectionModel. hasSelection ( )
返回类型

bool

返回 true if the selection model contains any selection ranges; otherwise returns false .

PySide2.QtCore.QItemSelectionModel. isColumnSelected ( column [ , parent=QModelIndex() ] )
参数
返回类型

bool

返回 true if all items are selected in the column 采用给定 parent .

Note that this function is usually faster than calling isSelected() on all items in the same column and that unselectable items are ignored.

注意

从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。

PySide2.QtCore.QItemSelectionModel. isRowSelected ( row [ , parent=QModelIndex() ] )
参数
返回类型

bool

返回 true if all items are selected in the row 采用给定 parent .

Note that this function is usually faster than calling isSelected() on all items in the same row and that unselectable items are ignored.

注意

从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。

PySide2.QtCore.QItemSelectionModel. isSelected ( index )
参数

index QModelIndex

返回类型

bool

返回 true 若给定模型项 index 被选中。

PySide2.QtCore.QItemSelectionModel. model ( )
返回类型

QAbstractItemModel

返回由选定模型操作的项模型。

另请参阅

setModel()

PySide2.QtCore.QItemSelectionModel. modelChanged ( model )
参数

model QAbstractItemModel

PySide2.QtCore.QItemSelectionModel. reset ( )

Clears the selection model. Does not emit any signals.

PySide2.QtCore.QItemSelectionModel. rowIntersectsSelection ( row [ , parent=QModelIndex() ] )
参数
返回类型

bool

返回 true 若有选中任何项在 row 采用给定 parent .

注意

从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。

PySide2.QtCore.QItemSelectionModel. select ( index , command )
参数
PySide2.QtCore.QItemSelectionModel. select ( selection , command )
参数
PySide2.QtCore.QItemSelectionModel. selectedColumns ( [ row=0 ] )
参数

row int

返回类型

QModelIndexList

返回的索引在给定 row 对于选中所有行的列而言。

PySide2.QtCore.QItemSelectionModel. selectedIndexes ( )
返回类型

QModelIndexList

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

PySide2.QtCore.QItemSelectionModel. selectedRows ( [ column=0 ] )
参数

column int

返回类型

QModelIndexList

返回的索引在给定 column 对于选中所有列的行而言。

PySide2.QtCore.QItemSelectionModel. selection ( )
返回类型

QItemSelection

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

PySide2.QtCore.QItemSelectionModel. selectionChanged ( selected , deselected )
参数
PySide2.QtCore.QItemSelectionModel. setCurrentIndex ( index , command )
参数

Sets the model item index to be the current item, and emits currentChanged() . The current item is used for keyboard navigation and focus indication; it is independent of any selected items, although a selected item can also be the current item.

从属指定 command index can also become part of the current selection.

PySide2.QtCore.QItemSelectionModel. setModel ( model )
参数

model QAbstractItemModel

将模型设为 model modelChanged() signal will be emitted.