|  | Home · All Classes · Modules

# QItemSelection Class Reference
[QtGui module]

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

### Methods

- __init__ (self)
- __init__ (self, QModelIndex, QModelIndex)
- __init__ (self, QItemSelection)
- append (self, QItemSelectionRange range)
- clear (self)
- bool contains (self, QModelIndex)
- int count (self, QItemSelectionRange range)
- int count (self)
- QItemSelectionRange first (self)
- list-of-QModelIndex indexes (self)
- int indexOf (self, QItemSelectionRange value, int from = 0)
- insert (self, int i, QItemSelectionRange range)
- bool isEmpty (self)
- QItemSelectionRange last (self)
- int lastIndexOf (self, QItemSelectionRange value, int from = -1)
- merge (self, QItemSelection, QItemSelectionModel.SelectionFlags)
- move (self, int from, int to)
- prepend (self, QItemSelectionRange range)
- int removeAll (self, QItemSelectionRange range)
- removeAt (self, int i)
- replace (self, int i, QItemSelectionRange range)
- select (self, QModelIndex, QModelIndex)
- swap (self, int i, int j)
- QItemSelectionRange takeAt (self, int i)
- QItemSelectionRange takeFirst (self)
- QItemSelectionRange takeLast (self)

### Static Methods

- split (QItemSelectionRange, QItemSelectionRange, QItemSelection)

### Special Methods

- int __contains__ (self, QModelIndex index)
- __delitem__ (self, int i)
- __delitem__ (self, slice slice)
- QItemSelectionRange __getitem__ (self, int i)
- QItemSelection __getitem__ (self, slice slice)
- QItemSelection __iadd__ (self, QItemSelection other)
- QItemSelection __iadd__ (self, QItemSelectionRange value)
- int __len__ (self)
- __setitem__ (self, int i, QItemSelectionRange range)
- __setitem__ (self, slice slice, QItemSelection list)

## Detailed Description

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

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`.

     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:

     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 Model/View Programming and QItemSelectionModel.

## Method Documentation

### QItemSelection.__init__ (self)

Constructs an empty selection.

### QItemSelection.__init__ (self, QModelIndex, QModelIndex)

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.

### QItemSelection.__init__ (self, QItemSelection)

### QItemSelection.append (self, QItemSelectionRange range)

### QItemSelection.clear (self)

### bool QItemSelection.contains (self, QModelIndex)

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

### int QItemSelection.count (self, QItemSelectionRange range)

### int QItemSelection.count (self)

### QItemSelectionRange QItemSelection.first (self)

### list-of-QModelIndex QItemSelection.indexes (self)

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

### int QItemSelection.indexOf (self, QItemSelectionRange value, int from = 0)

### QItemSelection.insert (self, int i, QItemSelectionRange range)

### bool QItemSelection.isEmpty (self)

### QItemSelectionRange QItemSelection.last (self)

### int QItemSelection.lastIndexOf (self, QItemSelectionRange value, int from = -1)

### QItemSelection.merge (self, QItemSelection, QItemSelectionModel.SelectionFlags)

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

### QItemSelection.move (self, int from, int to)

### QItemSelection.prepend (self, QItemSelectionRange range)

### int QItemSelection.removeAll (self, QItemSelectionRange range)

### QItemSelection.removeAt (self, int i)

### QItemSelection.replace (self, int i, QItemSelectionRange range)

### QItemSelection.select (self, QModelIndex, QModelIndex)

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.

### QItemSelection.split (QItemSelectionRange, QItemSelectionRange, QItemSelection)

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

### QItemSelection.swap (self, int i, int j)

### QItemSelectionRange QItemSelection.takeAt (self, int i)

### QItemSelectionRange QItemSelection.takeFirst (self)

### QItemSelectionRange QItemSelection.takeLast (self)

### int QItemSelection.__contains__ (self, QModelIndex index)

### QItemSelection.__delitem__ (self, int i)

### QItemSelection.__delitem__ (self, slice slice)

### QItemSelectionRange QItemSelection.__getitem__ (self, int i)

### QItemSelection QItemSelection.__getitem__ (self, slice slice)

### QItemSelection QItemSelection.__iadd__ (self, QItemSelection other)

### QItemSelection QItemSelection.__iadd__ (self, QItemSelectionRange value)

### int QItemSelection.__len__ (self)

### QItemSelection.__setitem__ (self, int i, QItemSelectionRange range)

### QItemSelection.__setitem__ (self, slice slice, QItemSelection list)