QItemSelectionModel#

The QItemSelectionModel class keeps track of a view’s selected items. More

Inheritance diagram of PySide6.QtCore.QItemSelectionModel

Synopsis#

Properties#

Functions#

Virtual functions#

Slots#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

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.

The QItemSelectionModel class is one of the Model/View Classes and is part of Qt’s model/view framework.

The selected items are stored using ranges. Whenever you want to modify the selected items use select() and provide either a QItemSelection , or a QModelIndex and a SelectionFlag .

The 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).

To update the currently selected items, use the bitwise OR of Current and any of the other SelectionFlags . If you omit the Current command, a new current selection will be created, and the previous one added to the whole selection. All functions operate on both layers; for example, selecteditems() will return items from both layers.

Note

Since 5.5, model , hasSelection , and currentIndex are meta-object properties.

class PySide6.QtCore.QItemSelectionModel([model=None])#

PySide6.QtCore.QItemSelectionModel(model, parent)

Parameters:

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

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

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtCore.QItemSelectionModel.currentIndex: PySide6.QtCore.QModelIndex#
Access functions:
property PᅟySide6.QtCore.QItemSelectionModel.hasSelection: bool#
Access functions:
property PᅟySide6.QtCore.QItemSelectionModel.model: PySide6.QtCore.QAbstractItemModel#
Access functions:
property PᅟySide6.QtCore.QItemSelectionModel.selectedIndexes: list of QModelIndex#
Access functions:
property PᅟySide6.QtCore.QItemSelectionModel.selection: PySide6.QtCore.QItemSelection#
Access functions:
PySide6.QtCore.QItemSelectionModel.SelectionFlag#

(inherits enum.Flag) This enum describes the way the selection model will be updated.

Constant

Description

QItemSelectionModel.NoUpdate

No selection will be made.

QItemSelectionModel.Clear

The complete selection will be cleared.

QItemSelectionModel.Select

All specified indexes will be selected.

QItemSelectionModel.Deselect

All specified indexes will be deselected.

QItemSelectionModel.Toggle

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

QItemSelectionModel.Current

The current selection will be updated.

QItemSelectionModel.Rows

All indexes will be expanded to span rows.

QItemSelectionModel.Columns

All indexes will be expanded to span 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.

PySide6.QtCore.QItemSelectionModel.clear()#

Clears the selection model. Emits selectionChanged() and currentChanged() .

PySide6.QtCore.QItemSelectionModel.clearCurrentIndex()#

Clears the current index. Emits currentChanged() .

PySide6.QtCore.QItemSelectionModel.clearSelection()#

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

PySide6.QtCore.QItemSelectionModel.columnIntersectsSelection(column[, parent=QModelIndex()])#
Parameters:
Return type:

bool

Returns true if there are any items selected in the column with the given parent.

Note

Since Qt 5.15, the default argument for parent is an empty model index.

PySide6.QtCore.QItemSelectionModel.currentChanged(current, previous)#
Parameters:

This signal is emitted whenever the current item changes. The previous model item index is replaced by the current index as the selection’s current item.

Note that this signal will not be emitted when the item model is reset.

Notification signal of property currentIndex .

PySide6.QtCore.QItemSelectionModel.currentColumnChanged(current, previous)#
Parameters:

This signal is emitted if the current item changes and its column is different to the column of the previous current item.

Note that this signal will not be emitted when the item model is reset.

PySide6.QtCore.QItemSelectionModel.currentIndex()#
Return type:

PySide6.QtCore.QModelIndex

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

Getter of property currentIndex .

PySide6.QtCore.QItemSelectionModel.currentRowChanged(current, previous)#
Parameters:

This signal is emitted if the current item changes and its row is different to the row of the previous current item.

Note that this signal will not be emitted when the item model is reset.

PySide6.QtCore.QItemSelectionModel.emitSelectionChanged(newSelection, oldSelection)#
Parameters:

Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.

PySide6.QtCore.QItemSelectionModel.hasSelection()#
Return type:

bool

Returns true if the selection model contains any selected item, otherwise returns false.

Getter of property hasSelection .

PySide6.QtCore.QItemSelectionModel.isColumnSelected(column[, parent=QModelIndex()])#
Parameters:
Return type:

bool

Returns true if all items are selected in the column with the given parent.

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

Note

Since Qt 5.15, the default argument for parent is an empty model index.

PySide6.QtCore.QItemSelectionModel.isRowSelected(row[, parent=QModelIndex()])#
Parameters:
Return type:

bool

Returns true if all items are selected in the row with the given parent.

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

Note

Since Qt 5.15, the default argument for parent is an empty model index.

PySide6.QtCore.QItemSelectionModel.isSelected(index)#
Parameters:

indexPySide6.QtCore.QModelIndex

Return type:

bool

Returns true if the given model item index is selected.

PySide6.QtCore.QItemSelectionModel.model()#
Return type:

PySide6.QtCore.QAbstractItemModel

Returns the item model operated on by the selection model.

See also

setModel()

Getter of property model .

PySide6.QtCore.QItemSelectionModel.modelChanged(model)#
Parameters:

modelPySide6.QtCore.QAbstractItemModel

This signal is emitted when the model is successfully set with setModel() .

See also

model() setModel()

Notification signal of property model .

PySide6.QtCore.QItemSelectionModel.reset()#

Clears the selection model. Does not emit any signals.

PySide6.QtCore.QItemSelectionModel.rowIntersectsSelection(row[, parent=QModelIndex()])#
Parameters:
Return type:

bool

Returns true if there are any items selected in the row with the given parent.

Note

Since Qt 5.15, the default argument for parent is an empty model index.

PySide6.QtCore.QItemSelectionModel.select(selection, command)#
Parameters:

Selects the item selection using the specified command, and emits selectionChanged() .

See also

SelectionFlag

PySide6.QtCore.QItemSelectionModel.select(index, command)
Parameters:

Selects the model item index using the specified command, and emits selectionChanged() .

See also

SelectionFlags

PySide6.QtCore.QItemSelectionModel.selectedColumns([row=0])#
Parameters:

row – int

Return type:

.list of QModelIndex

Returns the indexes in the given row for columns where all rows are selected.

PySide6.QtCore.QItemSelectionModel.selectedIndexes()#
Return type:

.list of QModelIndex

Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.

Getter of property selectedIndexes .

PySide6.QtCore.QItemSelectionModel.selectedRows([column=0])#
Parameters:

column – int

Return type:

.list of QModelIndex

Returns the indexes in the given column for the rows where all columns are selected.

PySide6.QtCore.QItemSelectionModel.selection()#
Return type:

PySide6.QtCore.QItemSelection

Returns the selection ranges stored in the selection model.

Getter of property selection .

PySide6.QtCore.QItemSelectionModel.selectionChanged(selected, deselected)#
Parameters:

This signal is emitted whenever the selection changes. The change in the selection is represented as an item selection of deselected items and an item selection of selected items.

Note the that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset.

Items which stay selected but change their index are not included in selected and deselected. Thus, this signal might be emitted with both selected and deselected empty, if only the indices of selected items change.

Notification signal of property hasSelection .

PySide6.QtCore.QItemSelectionModel.setCurrentIndex(index, command)#
Parameters:

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.

Depending on the specified command, the index can also become part of the current selection.

PySide6.QtCore.QItemSelectionModel.setModel(model)#
Parameters:

modelPySide6.QtCore.QAbstractItemModel

Sets the model to model. The modelChanged() signal will be emitted.

Setter of property model .