QItemSelectionModel¶
The
QItemSelectionModel
class keeps track of a view’s selected items. More…
Synopsis¶
Functions¶
def
columnIntersectsSelection
(column[, parent=QModelIndex()])def
currentIndex
()def
emitSelectionChanged
(newSelection, oldSelection)def
hasSelection
()def
isColumnSelected
(column[, parent=QModelIndex()])def
isRowSelected
(row[, parent=QModelIndex()])def
isSelected
(index)def
model
()def
rowIntersectsSelection
(row[, parent=QModelIndex()])def
selectedColumns
([row=0])def
selectedIndexes
()def
selectedRows
([column=0])def
selection
()def
setModel
(model)
Virtual functions¶
def
clear
()def
clearCurrentIndex
()def
reset
()def
select
(index, command)def
select
(selection, command)def
setCurrentIndex
(index, command)
Slots¶
def
clearSelection
()
Signals¶
def
currentChanged
(current, previous)def
currentColumnChanged
(current, previous)def
currentRowChanged
(current, previous)def
modelChanged
(model)def
selectionChanged
(selected, deselected)
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 aQItemSelection
, or aQModelIndex
and aSelectionFlag
.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 otherSelectionFlags
. If you omit theCurrent
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
, andcurrentIndex
are meta-object properties.
- class PySide2.QtCore.QItemSelectionModel([model=None])¶
PySide2.QtCore.QItemSelectionModel(model, parent)
- param parent:
- param model:
Constructs a selection model that operates on the specified item
model
.Constructs a selection model that operates on the specified item
model
withparent
.
- PySide2.QtCore.QItemSelectionModel.SelectionFlag¶
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.
- PySide2.QtCore.QItemSelectionModel.clear()¶
Clears the selection model. Emits
selectionChanged()
andcurrentChanged()
.
- PySide2.QtCore.QItemSelectionModel.clearCurrentIndex()¶
Clears the current index. Emits
currentChanged()
.
- PySide2.QtCore.QItemSelectionModel.clearSelection()¶
Clears the selection in the selection model. Emits
selectionChanged()
.
- PySide2.QtCore.QItemSelectionModel.columnIntersectsSelection(column[, parent=QModelIndex()])¶
- Parameters:
column – int
parent –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if there are any items selected in thecolumn
with the givenparent
.Note
Since Qt 5.15, the default argument for
parent
is an empty model index.
- PySide2.QtCore.QItemSelectionModel.currentChanged(current, previous)¶
- Parameters:
current –
PySide2.QtCore.QModelIndex
previous –
PySide2.QtCore.QModelIndex
- PySide2.QtCore.QItemSelectionModel.currentColumnChanged(current, previous)¶
- Parameters:
current –
PySide2.QtCore.QModelIndex
previous –
PySide2.QtCore.QModelIndex
- PySide2.QtCore.QItemSelectionModel.currentIndex()¶
- Return type:
- PySide2.QtCore.QItemSelectionModel.currentRowChanged(current, previous)¶
- Parameters:
current –
PySide2.QtCore.QModelIndex
previous –
PySide2.QtCore.QModelIndex
- PySide2.QtCore.QItemSelectionModel.emitSelectionChanged(newSelection, oldSelection)¶
- Parameters:
newSelection –
PySide2.QtCore.QItemSelection
oldSelection –
PySide2.QtCore.QItemSelection
Compares the two selections
newSelection
andoldSelection
and emitsselectionChanged()
with the deselected and selected items.
- PySide2.QtCore.QItemSelectionModel.hasSelection()¶
- Return type:
bool
- PySide2.QtCore.QItemSelectionModel.isColumnSelected(column[, parent=QModelIndex()])¶
- Parameters:
column – int
parent –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if all items are selected in thecolumn
with the givenparent
.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.
- PySide2.QtCore.QItemSelectionModel.isRowSelected(row[, parent=QModelIndex()])¶
- Parameters:
row – int
parent –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if all items are selected in therow
with the givenparent
.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.
- PySide2.QtCore.QItemSelectionModel.isSelected(index)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if the given model itemindex
is selected.
- PySide2.QtCore.QItemSelectionModel.model()¶
- Return type:
- PySide2.QtCore.QItemSelectionModel.modelChanged(model)¶
- Parameters:
- PySide2.QtCore.QItemSelectionModel.reset()¶
Clears the selection model. Does not emit any signals.
- PySide2.QtCore.QItemSelectionModel.rowIntersectsSelection(row[, parent=QModelIndex()])¶
- Parameters:
row – int
parent –
PySide2.QtCore.QModelIndex
- Return type:
bool
Returns
true
if there are any items selected in therow
with the givenparent
.Note
Since Qt 5.15, the default argument for
parent
is an empty model index.
- PySide2.QtCore.QItemSelectionModel.select(index, command)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
command –
SelectionFlags
- PySide2.QtCore.QItemSelectionModel.select(selection, command)
- Parameters:
selection –
PySide2.QtCore.QItemSelection
command –
SelectionFlags
- PySide2.QtCore.QItemSelectionModel.selectedColumns([row=0])¶
- Parameters:
row – int
- Return type:
QModelIndexList
Returns the indexes in the given
row
for columns where all rows are selected.See also
- PySide2.QtCore.QItemSelectionModel.selectedIndexes()¶
- Return type:
QModelIndexList
- PySide2.QtCore.QItemSelectionModel.selectedRows([column=0])¶
- Parameters:
column – int
- Return type:
QModelIndexList
Returns the indexes in the given
column
for the rows where all columns are selected.See also
- PySide2.QtCore.QItemSelectionModel.selection()¶
- Return type:
- PySide2.QtCore.QItemSelectionModel.selectionChanged(selected, deselected)¶
- Parameters:
selected –
PySide2.QtCore.QItemSelection
deselected –
PySide2.QtCore.QItemSelection
- PySide2.QtCore.QItemSelectionModel.setCurrentIndex(index, command)¶
- Parameters:
index –
PySide2.QtCore.QModelIndex
command –
SelectionFlags
Sets the model item
index
to be the current item, and emitscurrentChanged()
. 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
, theindex
can also become part of the current selection.See also
- PySide2.QtCore.QItemSelectionModel.setModel(model)¶
- Parameters:
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.