QItemSelectionModel Class
The QItemSelectionModel class keeps track of a view's selected items. More...
| Header: | #include <QItemSelectionModel> |
| qmake: | QT += core |
| Inherits: | QObject |
Public Types
| enum | SelectionFlag { NoUpdate, Clear, Select, Deselect, Toggle, …, ClearAndSelect } |
Properties
- selectedIndexes : const QModelIndexList
Public Functions
| QModelIndexList | selectedIndexes() const |
Signals
| void | selectionChanged(const QItemSelection &selected, const QItemSelection &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 a QItemSelection, or a QModelIndex and a QItemSelectionModel::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 QItemSelectionModel::Current and any of the other SelectionFlags. If you omit the QItemSelectionModel::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.
See also Model/View Programming, QAbstractItemModel, and Chart Example.
Member Type Documentation
enum QItemSelectionModel::SelectionFlag
This enum describes the way the selection model will be updated.
| Constant | Value | Description |
|---|---|---|
QItemSelectionModel::NoUpdate | 0x0000 | No selection will be made. |
QItemSelectionModel::Clear | 0x0001 | The complete selection will be cleared. |
QItemSelectionModel::Select | 0x0002 | All specified indexes will be selected. |
QItemSelectionModel::Deselect | 0x0004 | All specified indexes will be deselected. |
QItemSelectionModel::Toggle | 0x0008 | All specified indexes will be selected or deselected depending on their current state. |
QItemSelectionModel::Current | 0x0010 | The current selection will be updated. |
QItemSelectionModel::Rows | 0x0020 | All indexes will be expanded to span rows. |
QItemSelectionModel::Columns | 0x0040 | All indexes will be expanded to span columns. |
QItemSelectionModel::SelectCurrent | Select | Current | A combination of Select and Current, provided for convenience. |
QItemSelectionModel::ToggleCurrent | Toggle | Current | A combination of Toggle and Current, provided for convenience. |
QItemSelectionModel::ClearAndSelect | Clear | Select | A combination of Clear and Select, provided for convenience. |
Property Documentation
selectedIndexes : const QModelIndexList
This property was introduced in Qt 5.5.
Access functions:
| QModelIndexList | selectedIndexes() const |
Notifier signal:
| void | selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) |