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

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.

ConstantValueDescription
QItemSelectionModel::NoUpdate0x0000No selection will be made.
QItemSelectionModel::Clear0x0001The complete selection will be cleared.
QItemSelectionModel::Select0x0002All specified indexes will be selected.
QItemSelectionModel::Deselect0x0004All specified indexes will be deselected.
QItemSelectionModel::Toggle0x0008All specified indexes will be selected or deselected depending on their current state.
QItemSelectionModel::Current0x0010The current selection will be updated.
QItemSelectionModel::Rows0x0020All indexes will be expanded to span rows.
QItemSelectionModel::Columns0x0040All indexes will be expanded to span columns.
QItemSelectionModel::SelectCurrentSelect | CurrentA combination of Select and Current, provided for convenience.
QItemSelectionModel::ToggleCurrentToggle | CurrentA combination of Toggle and Current, provided for convenience.
QItemSelectionModel::ClearAndSelectClear | SelectA 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)