Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QItemSelectionModel Class Reference

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

    #include <QItemSelectionModel>

Inherits QObject.

- List of all members, including inherited members

### Public Types

- enum SelectionFlag { NoUpdate, Clear, Select, Deselect, Toggle, ..., ClearAndSelect }
- typedef SelectionFlags

### Writable Properties

- 1 writable property inherited from QObject

### Public Functions

- QItemSelectionModel ( QAbstractItemModel * model, QObject * parent = 0 )
- virtual ~QItemSelectionModel ()
- QModelIndex currentIndex () const
- bool isColumnSelected ( int column, const QModelIndex & parent ) const
- bool isRowSelected ( int row, const QModelIndex & parent ) const
- bool isSelected ( const QModelIndex & index ) const
- QAbstractItemModel * model () const
- QModelIndexList selectedIndexes () const

- 24 public functions inherited from QObject

### Public Slots

- virtual void clear ()
- virtual void reset ()
- virtual void select ( const QModelIndex & index, SelectionFlags command )
- virtual void select ( const QItemSelection & selection, SelectionFlags command )
- void setCurrentIndex ( const QModelIndex & index, SelectionFlags command )

- 1 public slot inherited from QObject

### Signals

- void currentChanged ( const QModelIndex & old, const QModelIndex & current )
- void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QObject

### Protected Functions

- void emitSelectionChanged ( const QItemSelection & newSelection, const QItemSelection & oldSelection )

- 9 protected functions inherited from QObject

## Detailed Description

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

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 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 committed selection. All functions operate on both layers; for example, selectedItems() will return items from both layers.

See also Model/View Programming and QAbstractItemModel.

## Member Type Documentation

### enum QItemSelectionModel::SelectionFlag
typedef QItemSelectionModel::SelectionFlags

This enum describes the way the selection model will be updated.

`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.

The SelectionFlags typedef can store a combination of SelectionFlag values.

## Member Function Documentation

### QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel * model, QObject * parent = 0 )

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

### QItemSelectionModel::~QItemSelectionModel () `[virtual]`

Destroys the selection model.

### void QItemSelectionModel::clear () `[virtual slot]`

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

### void QItemSelectionModel::currentChanged ( const QModelIndex & old, const QModelIndex & current ) `[signal]`

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

See also currentIndex() and setCurrentItem().

### QModelIndex QItemSelectionModel::currentIndex () const

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

### void QItemSelectionModel::emitSelectionChanged ( const QItemSelection & newSelection, const QItemSelection & oldSelection ) `[protected]`

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

### bool QItemSelectionModel::isColumnSelected ( int column, const QModelIndex & parent ) const

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

Note that this function is usually faster then calling isSelected() on all items in the same column.

### bool QItemSelectionModel::isRowSelected ( int row, const QModelIndex & parent ) const

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

Note that this function is usually faster then calling isSelected() on all items in the same row.

### bool QItemSelectionModel::isSelected ( const QModelIndex & index ) const

Returns true if the given model item index is selected.

### QAbstractItemModel * QItemSelectionModel::model () const

Returns the item model operated on by the selection model.

### void QItemSelectionModel::reset () `[virtual slot]`

Clears the selection model. Does not emit any signals.

### void QItemSelectionModel::select ( const QModelIndex & index, SelectionFlags command ) `[virtual slot]`

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

See also QItemSelectionModel::SelectionFlags.

### void QItemSelectionModel::select ( const QItemSelection & selection, SelectionFlags command ) `[virtual slot]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

See also QItemSelectionModel::SelectionFlag.

### QModelIndexList QItemSelectionModel::selectedIndexes () const

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

### void QItemSelectionModel::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) `[signal]`

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.

See also select().

### void QItemSelectionModel::setCurrentIndex ( const QModelIndex & index, SelectionFlags command ) `[slot]`

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.

See also select().