ItemSelectionModel QML Type | Qt 6.5
Description: Instantiates a <a href=

QItemSelectionModel to be used in conjunction with a QAbstractItemModel and any view supporting it.">

- Qt 6.5
- QML Types
- QtQml.Models
- ItemSelectionModel
- Qt 6.5.1 Reference Documentation

# ItemSelectionModel QML Type

Instantiates a QItemSelectionModel to be used in conjunction with a QAbstractItemModel and any view supporting it. More...

Import Statement: | import QtQml.Models
Instantiates: | QItemSelectionModel

- List of all members, including inherited members

## Properties

- currentIndex : QModelIndex
- hasSelection : bool
- model : QAbstractItemModel
- selectedIndexes : QModelIndexList
- selection : object

## Signals

- currentChanged(QModelIndex current, QModelIndex previous)
- selectionChanged(QItemSelection selected, QItemSelection deselected)

## Methods

- void clear()
- void clearCurrentIndex()
- void clearSelection()
- bool columnIntersectsSelection(int column, QModelIndex parent)
- bool isColumnSelected(int column, QModelIndex parent)
- bool isRowSelected(int row, QModelIndex parent)
- bool isSelected(QModelIndex index)
- void reset()
- bool rowIntersectsSelection(int row, QModelIndex parent)
- void select(QModelIndex index, SelectionFlags command)
- void select(QItemSelection selection, SelectionFlags command)
- QModelIndexList selectedColumns(int row)
- QModelIndexList selectedRows(int column)
- void setCurrentIndex(QModelIndex index, SelectionFlags command)

## Detailed Description

See also QItemSelectionModel and Models and Views in Qt Quick.

## Property Documentation

[read-only] currentIndex : QModelIndex

Use setCurrentIndex() to set its value.

See also setCurrentIndex() and currentChanged().

[read-only] hasSelection : bool

It will trigger property binding updates every time selectionChanged() is emitted, even though its value hasn't changed.

See also selection, selectedIndexes, select(), and selectionChanged().

model : QAbstractItemModel

This property's value must match the view's model.

[read-only] selectedIndexes : QModelIndexList

Contains the list of all the indexes in the selection model.

[read-only] selection : object

Holds the selection ranges stored in the selection model.

## Signal Documentation

currentChanged(QModelIndex current, QModelIndex previous)

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

Note that this signal will not be emitted when the item model is reset.

Note: The corresponding handler is `onCurrentChanged`.

See also currentIndex, setCurrentIndex(), and selectionChanged().

selectionChanged(QItemSelection selected, QItemSelection deselected)

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.

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.

Note: The corresponding handler is `onSelectionChanged`.

See also select() and currentChanged().

## Method Documentation

void clear()

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

void clearCurrentIndex()

Clears the current index. Emits currentChanged().

void clearSelection()

Clears the selection in the selection model. Emits selectionChanged().

bool columnIntersectsSelection(int column, QModelIndex parent)

Returns `true` if there are any items selected in the column with the given parent.

bool isColumnSelected(int column, QModelIndex parent)

Returns `true` if all items are selected in the column with 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.

bool isRowSelected(int row, QModelIndex parent)

Returns `true` if all items are selected in the row with 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.

bool isSelected(QModelIndex index)

Returns `true` if the given model item index is selected.

void reset()

Clears the selection model. Does not emit any signals.

bool rowIntersectsSelection(int row, QModelIndex parent)

Returns `true` if there are any items selected in the row with the given parent.

void select(QModelIndex index, SelectionFlags command)

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

Valid values for the command parameter, are:

Constant | Description
--- | ---
`NoUpdate` | No selection will be made.
`Clear` | The complete selection will be cleared.
`Select` | All specified indexes will be selected.
`Deselect` | All specified indexes will be deselected.
`Toggle` | All specified indexes will be selected or deselected depending on their current state.
`Current` | The current selection will be updated.
`Rows` | All indexes will be expanded to span rows.
`Columns` | All indexes will be expanded to span columns.
`SelectCurrent` | A combination of Select and Current, provided for convenience.
`ToggleCurrent` | A combination of Toggle and Current, provided for convenience.
`ClearAndSelect` | A combination of Clear and Select, provided for convenience.

void select(QItemSelection selection, SelectionFlags command)

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

Valid command values are described in select(index, command).

QModelIndexList selectedColumns(int row)

Returns the indexes in the given row for columns where all rows are selected.

See also selectedRows().

QModelIndexList selectedRows(int column)

Returns the indexes in the given column for the rows where all columns are selected.

See also selectedColumns().

void setCurrentIndex(QModelIndex index, SelectionFlags command)

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.

Valid command values are described in select(index, command).

See also select().