IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QItemSelection Class

The QItemSelection class manages information about selected items in a model.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QItemSelection Class

  • Header: QItemSelection

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Inherits: QList

  • Group: QItemSelection is part of model-view

Detailed Description

A QItemSelection describes the items in a model that have been selected by the user. A QItemSelection is basically a list of selection ranges, see QItemSelectionRange. It provides functions for creating and manipulating selections, and selecting a range of items from a model.

The QItemSelection class is one of the Model/View Classes and is part of Qt's model/view framework.

An item selection can be constructed and initialized to contain a range of items from an existing model. The following example constructs a selection that contains a range of items from the given model, beginning at the topLeft, and ending at the bottomRight.

 
Sélectionnez
QItemSelection *selection = new QItemSelection(topLeft, bottomRight);

An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way:

 
Sélectionnez
QItemSelection *selection = new QItemSelection();
...
selection->select(topLeft, bottomRight);

QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each item in the selection. Generally, an instance of this class will contain a list of non-overlapping selection ranges.

Use merge() to merge one item selection into another without making overlapping ranges. Use split() to split one selection range into smaller ranges based on a another selection range.

See Also

Member Function Documentation

 

QItemSelection::QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight)

Constructs an item selection that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight.

[default] QItemSelection::QItemSelection()

Constructs an empty selection.

bool QItemSelection::contains(const QModelIndex &index) const

Returns true if the selection contains the given index; otherwise returns false.

QModelIndexList QItemSelection::indexes() const

Returns a list of model indexes that correspond to the selected items.

void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)

Merges the other selection with this QItemSelection using the command given. This method guarantees that no ranges are overlapping.

Note that only QItemSelectionModel::Select, QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are supported.

See Also

See also split()

void QItemSelection::select(const QModelIndex &topLeft, const QModelIndex &bottomRight)

Adds the items in the range that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight to the list.

topLeft and bottomRight must have the same parent.

[static] void QItemSelection::split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result)

Splits the selection range using the selection other range. Removes all items in other from range and puts the result in result. This can be compared with the semantics of the subtract operation of a set.

See Also

See also merge()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+