class QItemSelection#

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

Synopsis#

Methods#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Warning

This section contains snippets that were automatically translated from C++ to Python and may contain errors.

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.

__init__(topLeft, bottomRight)#
Parameters:

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.

__init__()

Constructs an empty selection.

append(l)#
Parameters:

l – .list of QItemSelectionRange

append(arg__1)
Parameters:

arg__1QItemSelectionRange

at(i)#
Parameters:

i – int

Return type:

QItemSelectionRange

back()#
Return type:

QItemSelectionRange

capacity()#
Return type:

int

clear()#
constData()#
Return type:

QItemSelectionRange

constFirst()#
Return type:

QItemSelectionRange

constLast()#
Return type:

QItemSelectionRange

contains(index)#
Parameters:

indexQModelIndex

Return type:

bool

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

count()#
Return type:

int

data()#
Return type:

QItemSelectionRange

empty()#
Return type:

bool

first()#
Return type:

QItemSelectionRange

first(n)
Parameters:

n – int

Return type:

.list of QItemSelectionRange

static fromList(list)#
Parameters:

list – .list of QItemSelectionRange

Return type:

.list of QItemSelectionRange

static fromVector(vector)#
Parameters:

vector – .list of QItemSelectionRange

Return type:

.list of QItemSelectionRange

front()#
Return type:

QItemSelectionRange

indexes()#
Return type:

.list of QModelIndex

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

insert(arg__1, arg__2)#
Parameters:
isEmpty()#
Return type:

bool

isSharedWith(other)#
Parameters:

other – .list of QItemSelectionRange

Return type:

bool

last()#
Return type:

QItemSelectionRange

last(n)
Parameters:

n – int

Return type:

.list of QItemSelectionRange

length()#
Return type:

int

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

mid(pos[, len=-1])#
Parameters:
  • pos – int

  • len – int

Return type:

.list of QItemSelectionRange

move(from, to)#
Parameters:
  • from – int

  • to – int

__ne__(arg__1)#
Parameters:

arg__1QItemSelection

Return type:

bool

__add__(arg__1)#
Parameters:

arg__1QItemSelection

Return type:

QItemSelection

__iadd__(l)#
Parameters:

l – .list of QItemSelectionRange

Return type:

.list of QItemSelectionRange

__lshift__(l)#
Parameters:

l – .list of QItemSelectionRange

Return type:

.list of QItemSelectionRange

__eq__(arg__1)#
Parameters:

arg__1QItemSelection

Return type:

bool

operator(i)#
Parameters:

i – int

Return type:

QItemSelectionRange

pop_back()#
pop_front()#
prepend(arg__1)#
Parameters:

arg__1QItemSelectionRange

push_back(arg__1)#
Parameters:

arg__1QItemSelectionRange

push_front(arg__1)#
Parameters:

arg__1QItemSelectionRange

remove(i[, n=1])#
Parameters:
  • i – int

  • n – int

removeAll(arg__1)#
Parameters:

arg__1QItemSelectionRange

removeAt(i)#
Parameters:

i – int

removeFirst()#
removeLast()#
removeOne(arg__1)#
Parameters:

arg__1QItemSelectionRange

reserve(size)#
Parameters:

size – int

resize(size)#
Parameters:

size – int

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.

shrink_to_fit()#
size()#
Return type:

int

sliced(pos)#
Parameters:

pos – int

Return type:

.list of QItemSelectionRange

sliced(pos, n)
Parameters:
  • pos – int

  • n – int

Return type:

.list of QItemSelectionRange

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

squeeze()#
swap(other)#
Parameters:

other – .list of QItemSelectionRange

swapItemsAt(i, j)#
Parameters:
  • i – int

  • j – int

takeAt(i)#
Parameters:

i – int

Return type:

QItemSelectionRange

toList()#
Return type:

.list of QItemSelectionRange

toVector()#
Return type:

.list of QItemSelectionRange

value(i)#
Parameters:

i – int

Return type:

QItemSelectionRange