QItemSelection

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

Inheritance diagram of PySide2.QtCore.QItemSelection

Synopsis

Functions

Static functions

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 .

selection = 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:

selection = 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.

class PySide2.QtCore.QItemSelection

PySide2.QtCore.QItemSelection(QItemSelection)

PySide2.QtCore.QItemSelection(topLeft, bottomRight)

param QItemSelection:

PySide2.QtCore.QItemSelection

param topLeft:

PySide2.QtCore.QModelIndex

param bottomRight:

PySide2.QtCore.QModelIndex

Constructs an empty selection.

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 .

PySide2.QtCore.QItemSelection.append(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.append(t)
Parameters:

t

PySide2.QtCore.QItemSelection.at(i)
Parameters:

i – int

Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.back()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.clear()
PySide2.QtCore.QItemSelection.constFirst()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.constLast()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.contains(index)
Parameters:

indexPySide2.QtCore.QModelIndex

Return type:

bool

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

PySide2.QtCore.QItemSelection.count()
Return type:

int

PySide2.QtCore.QItemSelection.count(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

int

PySide2.QtCore.QItemSelection.detachShared()
PySide2.QtCore.QItemSelection.empty()
Return type:

bool

PySide2.QtCore.QItemSelection.endsWith(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

bool

PySide2.QtCore.QItemSelection.first()
Return type:

PySide2.QtCore.QItemSelectionRange

static PySide2.QtCore.QItemSelection.fromSet(set)
Parameters:

set

Return type:

Note

This function is deprecated.

static PySide2.QtCore.QItemSelection.fromVector(vector)
Parameters:

vector

Return type:

PySide2.QtCore.QItemSelection.front()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.indexOf(t[, from=0])
Parameters:
Return type:

int

PySide2.QtCore.QItemSelection.indexes()
Return type:

QModelIndexList

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

PySide2.QtCore.QItemSelection.insert(i, t)
Parameters:
PySide2.QtCore.QItemSelection.isEmpty()
Return type:

bool

PySide2.QtCore.QItemSelection.isSharedWith(other)
Parameters:

other

Return type:

bool

PySide2.QtCore.QItemSelection.last()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.lastIndexOf(t[, from=-1])
Parameters:
Return type:

int

PySide2.QtCore.QItemSelection.length()
Return type:

int

PySide2.QtCore.QItemSelection.merge(other, command)
Parameters:

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

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

See also

split()

PySide2.QtCore.QItemSelection.mid(pos[, length=-1])
Parameters:
  • pos – int

  • length – int

Return type:

PySide2.QtCore.QItemSelection.move(from, to)
Parameters:
  • from – int

  • to – int

PySide2.QtCore.QItemSelection.__ne__(l)
Parameters:

l

Return type:

bool

PySide2.QtCore.QItemSelection.__add__(l)
Parameters:

l

Return type:

PySide2.QtCore.QItemSelection.__iadd__(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

PySide2.QtCore.QItemSelection.__iadd__(l)
Parameters:

l

Return type:

PySide2.QtCore.QItemSelection.__lshift__(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

PySide2.QtCore.QItemSelection.__lshift__(l)
Parameters:

l

Return type:

PySide2.QtCore.QItemSelection.__eq__(l)
Parameters:

l

Return type:

bool

PySide2.QtCore.QItemSelection.operator[](i)
Parameters:

i – int

Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.pop_back()
PySide2.QtCore.QItemSelection.pop_front()
PySide2.QtCore.QItemSelection.prepend(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.push_back(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.push_front(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.removeAll(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

int

PySide2.QtCore.QItemSelection.removeAt(i)
Parameters:

i – int

PySide2.QtCore.QItemSelection.removeFirst()
PySide2.QtCore.QItemSelection.removeLast()
PySide2.QtCore.QItemSelection.removeOne(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

bool

PySide2.QtCore.QItemSelection.replace(i, t)
Parameters:
PySide2.QtCore.QItemSelection.reserve(size)
Parameters:

size – int

PySide2.QtCore.QItemSelection.select(topLeft, bottomRight)
Parameters:

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.

Note

topLeft and bottomRight must have the same parent.

PySide2.QtCore.QItemSelection.setSharable(sharable)
Parameters:

sharable – bool

PySide2.QtCore.QItemSelection.size()
Return type:

int

static PySide2.QtCore.QItemSelection.split(range, other, result)
Parameters:

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

merge()

PySide2.QtCore.QItemSelection.startsWith(t)
Parameters:

tPySide2.QtCore.QItemSelectionRange

Return type:

bool

PySide2.QtCore.QItemSelection.swap(i, j)
Parameters:
  • i – int

  • j – int

Note

This function is deprecated.

PySide2.QtCore.QItemSelection.swap(other)
Parameters:

other

PySide2.QtCore.QItemSelection.swapItemsAt(i, j)
Parameters:
  • i – int

  • j – int

PySide2.QtCore.QItemSelection.takeAt(i)
Parameters:

i – int

Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.takeFirst()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.takeLast()
Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.toSet()
Return type:

Note

This function is deprecated.

PySide2.QtCore.QItemSelection.toVector()
Return type:

PySide2.QtCore.QItemSelection.value(i)
Parameters:

i – int

Return type:

PySide2.QtCore.QItemSelectionRange

PySide2.QtCore.QItemSelection.value(i, defaultValue)
Parameters:
Return type:

PySide2.QtCore.QItemSelectionRange