PySide6.QtCore.QItemSelectionModel¶
- class QItemSelectionModel¶
- The - QItemSelectionModelclass keeps track of a view’s selected items. More…- Synopsis¶- Properties¶- Methods¶- def - __init__()
- def - currentIndex()
- def - hasSelection()
- def - isRowSelected()
- def - isSelected()
- def - model()
- def - selectedRows()
- def - selection()
- def - setModel()
 - Virtual methods¶- Slots¶- def - clearSelection()
 - Signals¶- def - currentChanged()
- def - modelChanged()
 - 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 - QItemSelectionModelkeeps 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 - QItemSelectionModelclass 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- QModelIndexand a- SelectionFlag.- The - QItemSelectionModeltakes 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 - Currentand any of the other- SelectionFlags. If you omit the- Currentcommand, 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.- class 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. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property currentIndexᅟ: QModelIndex¶
 - Access functions:
- Signal - currentChanged()
 
 - property hasSelectionᅟ: bool¶
 - Access functions:
- Signal - selectionChanged()
 
 - property modelᅟ: QAbstractItemModel¶
 - Access functions:
- Signal - modelChanged()
 
 - property selectedIndexesᅟ: list of QModelIndex¶
 - Access functions:
 - property selectionᅟ: QItemSelection¶
 - Access functions:
- Signal - selectionChanged()
 
 - __init__([model=None])¶
- Parameters:
- model – - QAbstractItemModel
 
 - Constructs a selection model that operates on the specified item - model.- __init__(model, parent)
- Parameters:
- model – - QAbstractItemModel
- parent – - QObject
 
 
 - Constructs a selection model that operates on the specified item - modelwith- parent.- clear()¶
 - Clears the selection model. Emits - selectionChanged()and- currentChanged().- clearCurrentIndex()¶
 - Clears the current index. Emits - currentChanged().- clearSelection()¶
 - Clears the selection in the selection model. Emits - selectionChanged().- columnIntersectsSelection(column[, parent=QModelIndex()])¶
- Parameters:
- column – int 
- parent – - QModelIndex
 
- Return type:
- bool 
 
 - Returns - trueif there are any items selected in the- columnwith the given- parent.- Note - Since Qt 5.15, the default argument for - parentis an empty model index.- currentChanged(current, previous)¶
- Parameters:
- current – - QModelIndex
- previous – - QModelIndex
 
 
 - This signal is emitted whenever the current item changes. The - previousmodel item index is replaced by the- currentindex 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ᅟ.- currentColumnChanged(current, previous)¶
- Parameters:
- current – - QModelIndex
- previous – - QModelIndex
 
 
 - This signal is emitted if the - currentitem changes and its column is different to the column of the- previouscurrent item.- Note that this signal will not be emitted when the item model is reset. - currentIndex()¶
- Return type:
 
 - Returns the model item index for the current item, or an invalid index if there is no current item. - See also - Getter of property - currentIndexᅟ.- currentRowChanged(current, previous)¶
- Parameters:
- current – - QModelIndex
- previous – - QModelIndex
 
 
 - This signal is emitted if the - currentitem changes and its row is different to the row of the- previouscurrent item.- Note that this signal will not be emitted when the item model is reset. - emitSelectionChanged(newSelection, oldSelection)¶
- Parameters:
- newSelection – - QItemSelection
- oldSelection – - QItemSelection
 
 
 - Compares the two selections - newSelectionand- oldSelectionand emits- selectionChanged()with the deselected and selected items.- hasSelection()¶
- Return type:
- bool 
 
 - Returns - trueif the selection model contains any selected item, otherwise returns- false.- Getter of property - hasSelectionᅟ.- isColumnSelected(column[, parent=QModelIndex()])¶
- Parameters:
- column – int 
- parent – - QModelIndex
 
- Return type:
- bool 
 
 - Returns - trueif all items are selected in the- columnwith 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 - parentis an empty model index.- isRowSelected(row[, parent=QModelIndex()])¶
- Parameters:
- row – int 
- parent – - QModelIndex
 
- Return type:
- bool 
 
 - Returns - trueif all items are selected in the- rowwith 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 - parentis an empty model index.- isSelected(index)¶
- Parameters:
- index – - QModelIndex
- Return type:
- bool 
 
 - Returns - trueif the given model item- indexis selected.- model()¶
- Return type:
 
 - Returns the item model operated on by the selection model. - Getter of property - modelᅟ.- modelChanged(model)¶
- Parameters:
- model – - QAbstractItemModel
 
 - This signal is emitted when the - modelis successfully set with- setModel().- See also - Notification signal of property - modelᅟ.- reset()¶
 - Clears the selection model. Does not emit any signals. - rowIntersectsSelection(row[, parent=QModelIndex()])¶
- Parameters:
- row – int 
- parent – - QModelIndex
 
- Return type:
- bool 
 
 - Returns - trueif there are any items selected in the- rowwith the given- parent.- Note - Since Qt 5.15, the default argument for - parentis an empty model index.- select(selection, command)¶
- Parameters:
- selection – - QItemSelection
- command – Combination of - SelectionFlag
 
 
 - Selects the item - selectionusing the specified- command, and emits- selectionChanged().- See also - select(index, command)
- Parameters:
- index – - QModelIndex
- command – Combination of - SelectionFlag
 
 
 - Selects the model item - indexusing the specified- command, and emits- selectionChanged().- See also - SelectionFlags- selectedColumns([row=0])¶
- Parameters:
- row – int 
- Return type:
- .list of QModelIndex 
 
 - Returns the indexes in the given - rowfor columns where all rows are selected.- See also - 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ᅟ.- selectedRows([column=0])¶
- Parameters:
- column – int 
- Return type:
- .list of QModelIndex 
 
 - Returns the indexes in the given - columnfor the rows where all columns are selected.- See also - selection()¶
- Return type:
 
 - Returns the selection ranges stored in the selection model. - Getter of property - selectionᅟ.- selectionChanged(selected, deselected)¶
- Parameters:
- selected – - QItemSelection
- deselected – - QItemSelection
 
 
 - This signal is emitted whenever the selection changes. The change in the selection is represented as an item selection of - deselecteditems and an item selection of- selecteditems.- 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 - selectedand- deselected. Thus, this signal might be emitted with both- selectedand- deselectedempty, if only the indices of selected items change.- See also - Notification signal of property - hasSelectionᅟ.- setCurrentIndex(index, command)¶
- Parameters:
- index – - QModelIndex
- command – Combination of - SelectionFlag
 
 
 - Sets the model item - indexto 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- indexcan also become part of the current selection.- See also - setModel(model)¶
- Parameters:
- model – - QAbstractItemModel
 
 - Sets the model to - model. The- modelChanged()signal will be emitted.- See also - Setter of property - modelᅟ.