Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QItemSelectionModel Class Reference

[38] More...

#include <qitemselectionmodel.h>

+ Inheritance diagram for QItemSelectionModel:
+ Collaboration diagram for QItemSelectionModel:

Public Types

enum  SelectionFlag {
  NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 ,
  Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 ,
  SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 ,
  Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 ,
  Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current ,
  ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select
}
 This enum describes the way the selection model will be updated. More...
 
enum  SelectionFlag {
  NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 ,
  Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 ,
  SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 ,
  Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 ,
  Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current ,
  ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select
}
 

Public Slots

virtual void setCurrentIndex (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 Sets the model item index to be the current item, and emits currentChanged().
 
virtual void select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 Selects the model item index using the specified command, and emits selectionChanged().
 
virtual void select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
 Selects the item selection using the specified command, and emits selectionChanged().
 
virtual void clear ()
 Clears the selection model.
 
virtual void reset ()
 Clears the selection model.
 
void clearSelection ()
 
virtual void clearCurrentIndex ()
 Clears the current index.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 This signal is emitted whenever the selection changes.
 
void currentChanged (const QModelIndex &current, const QModelIndex &previous)
 This signal is emitted whenever the current item changes.
 
void currentRowChanged (const QModelIndex &current, const QModelIndex &previous)
 This signal is emitted if the current item changes and its row is different to the row of the previous current item.
 
void currentColumnChanged (const QModelIndex &current, const QModelIndex &previous)
 This signal is emitted if the current item changes and its column is different to the column of the previous current item.
 
void modelChanged (QAbstractItemModel *model)
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QItemSelectionModel (QAbstractItemModel *model=nullptr)
 Constructs a selection model that operates on the specified item model.
 
 QItemSelectionModel (QAbstractItemModel *model, QObject *parent)
 Constructs a selection model that operates on the specified item model with parent.
 
virtual ~QItemSelectionModel ()
 Destroys the selection model.
 
QModelIndex currentIndex () const
 Returns the model item index for the current item, or an invalid index if there is no current item.
 
Q_INVOKABLE bool isSelected (const QModelIndex &index) const
 Returns true if the given model item index is selected.
 
Q_INVOKABLE bool isRowSelected (int row, const QModelIndex &parent=QModelIndex()) const
 Returns true if all items are selected in the row with the given parent.
 
Q_INVOKABLE bool isColumnSelected (int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if all items are selected in the column with the given parent.
 
Q_INVOKABLE bool rowIntersectsSelection (int row, const QModelIndex &parent=QModelIndex()) const
 Returns true if there are any items selected in the row with the given parent.
 
Q_INVOKABLE bool columnIntersectsSelection (int column, const QModelIndex &parent=QModelIndex()) const
 Returns true if there are any items selected in the column with the given parent.
 
bool hasSelection () const
 
QModelIndexList selectedIndexes () const
 Returns a list of all selected model item indexes.
 
Q_INVOKABLE QModelIndexList selectedRows (int column=0) const
 
Q_INVOKABLE QModelIndexList selectedColumns (int row=0) const
 
const QItemSelection selection () const
 Returns the selection ranges stored in the selection model.
 
const QAbstractItemModelmodel () const
 Returns the item model operated on by the selection model.
 
QAbstractItemModelmodel ()
 
QBindable< QAbstractItemModel * > bindableModel ()
 
void setModel (QAbstractItemModel *model)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Protected Member Functions

 QItemSelectionModel (QItemSelectionModelPrivate &dd, QAbstractItemModel *model)
 
void emitSelectionChanged (const QItemSelection &newSelection, const QItemSelection &oldSelection)
 Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

QAbstractItemModelmodel
 
bool hasSelection
 
QModelIndex currentIndex
 
QItemSelection selection
 
QModelIndexList selectedIndexes
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

[38]

\inmodule QtCore

[39]

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 QItemSelectionModel class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{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, \l {QTableWidget::selectedItems()}{selecteditems()} will return items from both layers.

Note
Since 5.5, \l{QItemSelectionModel::model()}{model}, \l{QItemSelectionModel::hasSelection()}{hasSelection}, and \l{QItemSelectionModel::currentIndex()}{currentIndex} are meta-object properties.
See also
{Model/View Programming}, QAbstractItemModel

Definition at line 336 of file src_corelib_kernel_qobject.cpp.

Member Enumeration Documentation

◆ SelectionFlag [1/2]

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

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

Enumerator
NoUpdate 
Clear 
Select 
Deselect 
Toggle 
Current 
Rows 
Columns 
SelectCurrent 
ToggleCurrent 
ClearAndSelect 
NoUpdate 
Clear 
Select 
Deselect 
Toggle 
Current 
Rows 
Columns 
SelectCurrent 
ToggleCurrent 
ClearAndSelect 

Definition at line 342 of file src_corelib_kernel_qobject.cpp.

◆ SelectionFlag [2/2]

Enumerator
NoUpdate 
Clear 
Select 
Deselect 
Toggle 
Current 
Rows 
Columns 
SelectCurrent 
ToggleCurrent 
ClearAndSelect 
NoUpdate 
Clear 
Select 
Deselect 
Toggle 
Current 
Rows 
Columns 
SelectCurrent 
ToggleCurrent 
ClearAndSelect 

Definition at line 108 of file qitemselectionmodel.h.

Constructor & Destructor Documentation

◆ QItemSelectionModel() [1/3]

QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel * model = nullptr)
explicit

Constructs a selection model that operates on the specified item model.

Definition at line 1136 of file qitemselectionmodel.cpp.

References model.

◆ QItemSelectionModel() [2/3]

QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel * model,
QObject * parent )
explicit

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

Definition at line 1145 of file qitemselectionmodel.cpp.

References model.

◆ ~QItemSelectionModel()

QItemSelectionModel::~QItemSelectionModel ( )
virtual

Destroys the selection model.

Definition at line 1163 of file qitemselectionmodel.cpp.

◆ QItemSelectionModel() [3/3]

QItemSelectionModel::QItemSelectionModel ( QItemSelectionModelPrivate & dd,
QAbstractItemModel * model )
protected

Definition at line 1154 of file qitemselectionmodel.cpp.

References QItemSelectionModelPrivate::initModel(), and model.

+ Here is the call graph for this function:

Member Function Documentation

◆ bindableModel()

QBindable< QAbstractItemModel * > QItemSelectionModel::bindableModel ( )

Definition at line 1875 of file qitemselectionmodel.cpp.

◆ clear

void QItemSelectionModel::clear ( )
virtualslot

Clears the selection model.

Emits selectionChanged() and currentChanged().

Definition at line 1335 of file qitemselectionmodel.cpp.

References clearCurrentIndex(), and clearSelection().

Referenced by QListWidget::clear(), QTableWidget::clear(), QTreeWidget::clear(), QTableWidget::clearContents(), reset(), QSidebar::selectUrl(), QCompleterPrivate::setCurrentIndex(), QTreeView::setSelection(), and QCalendarWidgetPrivate::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearCurrentIndex

void QItemSelectionModel::clearCurrentIndex ( )
virtualslot

Clears the current index.

Emits currentChanged().

Definition at line 1344 of file qitemselectionmodel.cpp.

References currentChanged(), currentColumnChanged(), currentRowChanged(), d, emit, and QModelIndex::isValid().

Referenced by clear().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearSelection

void QItemSelectionModel::clearSelection ( )
slot
Since
4.2 Clears the selection in the selection model. Emits selectionChanged().

Definition at line 1369 of file qitemselectionmodel.cpp.

References Clear, d, and select().

Referenced by clear(), and QQuickTableViewPrivate::clearSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ columnIntersectsSelection()

bool QItemSelectionModel::columnIntersectsSelection ( int column,
const QModelIndex & parent = QModelIndex() ) const

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

Note
Since Qt 5.15, the default argument for parent is an empty model index.

Definition at line 1651 of file qitemselectionmodel.cpp.

References d, isSelectableAndEnabled(), j, QItemSelection::merge(), and QObject::parent().

Referenced by QHeaderViewPrivate::columnIntersectsSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentChanged

void QItemSelectionModel::currentChanged ( const QModelIndex & current,
const QModelIndex & previous )
signal

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.

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

Referenced by QTreeWidget::QTreeWidget(), clearCurrentIndex(), QFileDialogPrivate::createWidgets(), QSidebar::selectUrl(), setCurrentIndex(), QComboBox::setModel(), QSidebar::setModelAndUrls(), QAbstractItemView::setSelectionModel(), QQuickTableView::setSelectionModel(), QListWidget::setSelectionModel(), QTableWidgetPrivate::setup(), and QComboBoxPrivate::viewContainer().

+ Here is the caller graph for this function:

◆ currentColumnChanged

void QItemSelectionModel::currentColumnChanged ( const QModelIndex & current,
const QModelIndex & previous )
signal

This signal is emitted if the current item changes and its column is different to the column of the previous current item.

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

See also
currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex()

Referenced by clearCurrentIndex(), and setCurrentIndex().

+ Here is the caller graph for this function:

◆ currentIndex()

QModelIndex QItemSelectionModel::currentIndex ( ) const

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

Definition at line 1418 of file qitemselectionmodel.cpp.

◆ currentRowChanged

void QItemSelectionModel::currentRowChanged ( const QModelIndex & current,
const QModelIndex & previous )
signal

This signal is emitted if the current item changes and its row is different to the row of the previous current item.

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

See also
currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex()

Referenced by clearCurrentIndex(), QInputDialogPrivate::ensureListView(), setCurrentIndex(), QTableView::setSelectionModel(), and QTreeView::setSelectionModel().

+ Here is the caller graph for this function:

◆ emitSelectionChanged()

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.

Definition at line 1901 of file qitemselectionmodel.cpp.

References QList< T >::append(), QList< T >::at(), emit, i, QItemSelectionRange::intersects(), QList< T >::isEmpty(), o, QList< T >::removeAt(), selectionChanged(), QList< T >::size(), and QItemSelection::split().

Referenced by select().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSelection()

bool QItemSelectionModel::hasSelection ( ) const
Since
4.2

Returns true if the selection model contains any selected item, otherwise returns false.

Definition at line 1698 of file qitemselectionmodel.cpp.

References d, Deselect, QAbstractItemModelPrivate::executePendingOperations(), QObjectPrivate::get(), QItemSelection::merge(), model, selectionIsEmpty(), and Toggle.

+ Here is the call graph for this function:

◆ isColumnSelected()

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

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.

Note
Since Qt 5.15, the default argument for parent is an empty model index.

Definition at line 1543 of file qitemselectionmodel.cpp.

References QSet< T >::constBegin(), QSet< T >::constEnd(), d, Deselect, i, isSelectableAndEnabled(), it, j, QObject::parent(), qMax(), and Toggle.

Referenced by QHeaderViewPrivate::isColumnSelected(), and selectedColumns().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRowSelected()

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

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.

Note
Since Qt 5.15, the default argument for parent is an empty model index.

Definition at line 1469 of file qitemselectionmodel.cpp.

References QSet< T >::constBegin(), QSet< T >::constEnd(), d, Deselect, i, isSelectableAndEnabled(), it, j, QObject::parent(), qMax(), and Toggle.

Referenced by QHeaderViewPrivate::isRowSelected().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSelected()

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

Returns true if the given model item index is selected.

Definition at line 1426 of file qitemselectionmodel.cpp.

References QSet< T >::begin(), d, Deselect, QSet< T >::end(), isSelectableAndEnabled(), it, Select, and Toggle.

Referenced by QTableViewPrivate::drawCell(), QAbstractItemViewPrivate::extendedSelectionCommand(), QQuickTableViewPrivate::handleTap(), QTableWidgetItem::isSelected(), QAbstractItemView::mousePressEvent(), QListView::paintEvent(), QQuickTableViewPrivate::selectedInSelectionModel(), QAbstractItemViewPrivate::shouldEdit(), and QQuickTableViewPrivate::startSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ model() [1/2]

QAbstractItemModel * QItemSelectionModel::model ( )

◆ model() [2/2]

const QAbstractItemModel * QItemSelectionModel::model ( ) const

Returns the item model operated on by the selection model.

Definition at line 1870 of file qitemselectionmodel.cpp.

◆ modelChanged

void QItemSelectionModel::modelChanged ( QAbstractItemModel * model)
signal
Since
5.5

This signal is emitted when the model is successfully set with setModel().

See also
model(), setModel()

◆ reset

void QItemSelectionModel::reset ( )
virtualslot

Clears the selection model.

Does not emit any signals.

Definition at line 1359 of file qitemselectionmodel.cpp.

References clear().

Referenced by QItemSelectionModelPrivate::initModel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rowIntersectsSelection()

bool QItemSelectionModel::rowIntersectsSelection ( int row,
const QModelIndex & parent = QModelIndex() ) const

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

Note
Since Qt 5.15, the default argument for parent is an empty model index.

Definition at line 1616 of file qitemselectionmodel.cpp.

References d, isSelectableAndEnabled(), j, QItemSelection::merge(), and QObject::parent().

Referenced by QHeaderViewPrivate::rowIntersectsSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select [1/2]

void QItemSelectionModel::select ( const QItemSelection & selection,
QItemSelectionModel::SelectionFlags command )
virtualslot

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

See also
QItemSelectionModel::SelectionFlag

Definition at line 1284 of file qitemselectionmodel.cpp.

References Clear, Columns, Current, d, Deselect, emitSelectionChanged(), QItemSelection::merge(), NoUpdate, qWarning, QList< T >::removeIf(), Rows, Select, selection, and Toggle.

+ Here is the call graph for this function:

◆ select [2/2]

void QItemSelectionModel::select ( const QModelIndex & index,
QItemSelectionModel::SelectionFlags command )
virtualslot

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

See also
QItemSelectionModel::SelectionFlags

Definition at line 1173 of file qitemselectionmodel.cpp.

References select(), and selection.

Referenced by clearSelection(), main(), select(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QTableViewPrivate::selectColumn(), QTableViewPrivate::selectRow(), QSidebar::selectUrl(), setCurrentIndex(), QTableWidget::setRangeSelected(), QTableWidgetItem::setSelected(), QTreeWidgetItem::setSelected(), QQuickTableViewPrivate::updateSelection(), and QQuickTreeViewPrivate::updateSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ selectedColumns()

QModelIndexList QItemSelectionModel::selectedColumns ( int row = 0) const
Since
4.2 Returns the indexes in the given row for columns where all rows are selected.
See also
selectedIndexes(), selectedRows()

Definition at line 1791 of file qitemselectionmodel.cpp.

References QList< T >::append(), QList< T >::at(), i, QAbstractItemModel::index(), isColumnSelected(), model, QObject::parent(), selection, and QList< T >::size().

Referenced by QTableViewPrivate::selectColumn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ selectedIndexes()

QModelIndexList QItemSelectionModel::selectedIndexes ( ) const

Returns a list of all selected model item indexes.

The list contains no duplicates, and is not sorted.

Definition at line 1728 of file qitemselectionmodel.cpp.

References d, QItemSelection::indexes(), and QItemSelection::merge().

+ Here is the call graph for this function:

◆ selectedRows()

QModelIndexList QItemSelectionModel::selectedRows ( int column = 0) const
Since
4.2 Returns the indexes in the given column for the rows where all columns are selected.
See also
selectedIndexes(), selectedColumns()

Definition at line 1762 of file qitemselectionmodel.cpp.

References QList< T >::append(), QList< T >::at(), i, QAbstractTableModel::index(), model, QModelIndex::parent(), selection, and QList< T >::size().

Referenced by QInputDialogPrivate::listViewText(), and QTableViewPrivate::selectRow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ selection()

const QItemSelection QItemSelectionModel::selection ( ) const

Returns the selection ranges stored in the selection model.

Definition at line 1816 of file qitemselectionmodel.cpp.

References d, QItemSelection::merge(), and QList< T >::removeIf().

+ Here is the call graph for this function:

◆ selectionChanged

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.

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 selected and deselected. Thus, this signal might be emitted with both selected and deselected empty, if only the indices of selected items change.

See also
select(), currentChanged()

Referenced by QTreeWidget::QTreeWidget(), QFileDialogPrivate::createWidgets(), emitSelectionChanged(), QAbstractItemView::setSelectionModel(), QQuickTableView::setSelectionModel(), QListWidget::setSelectionModel(), and QTableWidgetPrivate::setup().

+ Here is the caller graph for this function:

◆ setCurrentIndex

void QItemSelectionModel::setCurrentIndex ( const QModelIndex & index,
QItemSelectionModel::SelectionFlags command )
virtualslot

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()

Definition at line 1389 of file qitemselectionmodel.cpp.

References QPersistentModelIndex::column(), currentChanged(), currentColumnChanged(), currentRowChanged(), d, emit, NoUpdate, QPersistentModelIndex::parent(), qWarning, QPersistentModelIndex::row(), and select().

Referenced by QAbstractItemView::focusInEvent(), QtPrivate::QCalendarView::mouseMoveEvent(), QtPrivate::QCalendarView::mousePressEvent(), QTableViewPrivate::selectColumn(), QTableViewPrivate::selectRow(), QQuickTableViewPrivate::setCurrentIndex(), QCompleterPrivate::setCurrentIndex(), QQuickTableViewPrivate::setCurrentIndexFromKeyEvent(), QListWidget::setCurrentRow(), QInputDialogPrivate::setListViewText(), QCalendarWidgetPrivate::update(), and QCalendarWidgetPrivate::updateCurrentPage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setModel()

void QItemSelectionModel::setModel ( QAbstractItemModel * model)
Since
5.5

Sets the model to model. The modelChanged() signal will be emitted.

See also
model(), modelChanged()

Definition at line 1887 of file qitemselectionmodel.cpp.

References d, and model.

Property Documentation

◆ currentIndex

◆ hasSelection

◆ model

◆ selectedIndexes

QItemSelectionModel::selectedIndexes
read

◆ selection


The documentation for this class was generated from the following files: