|  | Home · All Classes · Modules

# QListView Class Reference
[QtGui module]

The QListView class provides a list or icon view onto a model. More...

Inherits QAbstractItemView.

Inherited by QHelpIndexWidget, QListWidget and QUndoView.

### Types

- enum Flow { LeftToRight, TopToBottom }
- enum LayoutMode { SinglePass, Batched }
- enum Movement { Static, Free, Snap }
- enum ResizeMode { Fixed, Adjust }
- enum ViewMode { ListMode, IconMode }

### Methods

- __init__ (self, QWidget parent = None)
- int batchSize (self)
- clearPropertyFlags (self)
- currentChanged (self, QModelIndex, QModelIndex)
- dataChanged (self, QModelIndex, QModelIndex)
- doItemsLayout (self)
- dragLeaveEvent (self, QDragLeaveEvent)
- dragMoveEvent (self, QDragMoveEvent)
- dropEvent (self, QDropEvent)
- bool event (self, QEvent)
- Flow flow (self)
- QSize gridSize (self)
- int horizontalOffset (self)
- QModelIndex indexAt (self, QPoint)
- bool isIndexHidden (self, QModelIndex)
- bool isRowHidden (self, int)
- bool isSelectionRectVisible (self)
- bool isWrapping (self)
- LayoutMode layoutMode (self)
- int modelColumn (self)
- mouseMoveEvent (self, QMouseEvent)
- mouseReleaseEvent (self, QMouseEvent)
- QModelIndex moveCursor (self, QAbstractItemView.CursorAction, Qt.KeyboardModifiers)
- Movement movement (self)
- paintEvent (self, QPaintEvent)
- QRect rectForIndex (self, QModelIndex)
- reset (self)
- resizeEvent (self, QResizeEvent)
- ResizeMode resizeMode (self)
- rowsAboutToBeRemoved (self, QModelIndex, int, int)
- rowsInserted (self, QModelIndex, int, int)
- scrollContentsBy (self, int, int)
- scrollTo (self, QModelIndex, QAbstractItemView.ScrollHint hint = QAbstractItemView.EnsureVisible)
- list-of-QModelIndex selectedIndexes (self)
- selectionChanged (self, QItemSelection, QItemSelection)
- setBatchSize (self, int)
- setFlow (self, Flow)
- setGridSize (self, QSize)
- setLayoutMode (self, LayoutMode)
- setModelColumn (self, int)
- setMovement (self, Movement)
- setPositionForIndex (self, QPoint, QModelIndex)
- setResizeMode (self, ResizeMode)
- setRootIndex (self, QModelIndex)
- setRowHidden (self, int, bool)
- setSelection (self, QRect, QItemSelectionModel.SelectionFlags)
- setSelectionRectVisible (self, bool)
- setSpacing (self, int)
- setUniformItemSizes (self, bool)
- setViewMode (self, ViewMode)
- setWordWrap (self, bool)
- setWrapping (self, bool)
- int spacing (self)
- startDrag (self, Qt.DropActions)
- timerEvent (self, QTimerEvent)
- bool uniformItemSizes (self)
- updateGeometries (self)
- int verticalOffset (self)
- ViewMode viewMode (self)
- QStyleOptionViewItem viewOptions (self)
- QRect visualRect (self, QModelIndex)
- QRegion visualRegionForSelection (self, QItemSelection)
- bool wordWrap (self)

### Qt Signals

- void indexesMoved (const QModelIndexList&)

## Detailed Description

The QListView class provides a list or icon view onto a model.

A QListView presents items stored in a model, either as a simple non-hierarchical list, or as a collection of icons. This class is used to provide lists and icon views that were previously provided by the `QListBox` and `QIconView` classes, but using the more flexible approach provided by Qt's model/view architecture.

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

This view does not display horizontal or vertical headers; to display a list of items with a horizontal header, use QTreeView instead.

QListView implements the interfaces defined by the QAbstractItemView class to allow it to display data provided by models derived from the QAbstractItemModel class.

Items in a list view can be displayed using one of two view modes: In ListMode, the items are displayed in the form of a simple list; in IconMode, the list view takes the form of an icon view in which the items are displayed with icons like files in a file manager. By default, the list view is in ListMode. To change the view mode, use the setViewMode() function, and to determine the current view mode, use viewMode().

Items in these views are laid out in the direction specified by the flow() of the list view. The items may be fixed in place, or allowed to move, depending on the view's movement() state.

If the items in the model cannot be completely laid out in the direction of flow, they can be wrapped at the boundary of the view widget; this depends on isWrapping(). This property is useful when the items are being represented by an icon view.

The resizeMode() and layoutMode() govern how and when the items are laid out. Items are spaced according to their spacing(), and can exist within a notional grid of size specified by gridSize(). The items can be rendered as large or small icons depending on their iconSize().

A Windows XP style list view. | A Macintosh style list view. | A Plastique style list view.

### Improving Performance

It is possible to give the view hints about the data it is handling in order to improve its performance when displaying large numbers of items. One approach that can be taken for views that are intended to display items with equal sizes is to set the uniformItemSizes property to true.

See also View Classes, QTreeView, QTableView, and QListWidget.

## Type Documentation

### QListView.Flow

Constant | Value | Description
--- | --- | ---
`QListView.LeftToRight` | `0` | The items are laid out in the view from the left to the right.
`QListView.TopToBottom` | `1` | The items are laid out in the view from the top to the bottom.

### QListView.LayoutMode

Constant | Value | Description
--- | --- | ---
`QListView.SinglePass` | `0` | The items are laid out all at once.
`QListView.Batched` | `1` | The items are laid out in batches of batchSize items.

See also batchSize.

### QListView.Movement

Constant | Value | Description
--- | --- | ---
`QListView.Static` | `0` | The items cannot be moved by the user.
`QListView.Free` | `1` | The items can be moved freely by the user.
`QListView.Snap` | `2` | The items snap to the specified grid when moved; see setGridSize().

### QListView.ResizeMode

Constant | Value | Description
--- | --- | ---
`QListView.Fixed` | `0` | The items will only be laid out the first time the view is shown.
`QListView.Adjust` | `1` | The items will be laid out every time the view is resized.

### QListView.ViewMode

Constant | Value | Description
--- | --- | ---
`QListView.ListMode` | `0` | The items are laid out using TopToBottom flow, with Small size and Static movement
`QListView.IconMode` | `1` | The items are laid out using LeftToRight flow, with Large size and Free movement

## Method Documentation

### QListView.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Creates a new QListView with the given parent to view a model. Use setModel() to set the model.

### int QListView.batchSize (self)

### QListView.clearPropertyFlags (self)

Clears the QListView-specific property flags. See viewMode.

Properties inherited from QAbstractItemView are not covered by the property flags. Specifically, dragEnabled and acceptsDrops are computed by QListView when calling setMovement() or setViewMode().

### QListView.currentChanged (self, QModelIndex, QModelIndex)

Reimplemented from QAbstractItemView.currentChanged().

### QListView.dataChanged (self, QModelIndex, QModelIndex)

Reimplemented from QAbstractItemView.dataChanged().

### QListView.doItemsLayout (self)

### QListView.dragLeaveEvent (self, QDragLeaveEvent)

Reimplemented from QWidget.dragLeaveEvent().

### QListView.dragMoveEvent (self, QDragMoveEvent)

Reimplemented from QWidget.dragMoveEvent().

### QListView.dropEvent (self, QDropEvent)

Reimplemented from QWidget.dropEvent().

### bool QListView.event (self, QEvent)

Reimplemented from QObject.event().

### Flow QListView.flow (self)

### QSize QListView.gridSize (self)

### int QListView.horizontalOffset (self)

Reimplemented from QAbstractItemView.horizontalOffset().

### QModelIndex QListView.indexAt (self, QPoint)

Reimplemented from QAbstractItemView.indexAt().

### bool QListView.isIndexHidden (self, QModelIndex)

Reimplemented from QAbstractItemView.isIndexHidden().

### bool QListView.isRowHidden (self, int)

Returns true if the row is hidden; otherwise returns false.

### bool QListView.isSelectionRectVisible (self)

### bool QListView.isWrapping (self)

### LayoutMode QListView.layoutMode (self)

### int QListView.modelColumn (self)

### QListView.mouseMoveEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseMoveEvent().

### QListView.mouseReleaseEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseReleaseEvent().

### QModelIndex QListView.moveCursor (self, QAbstractItemView.CursorAction, Qt.KeyboardModifiers)

Reimplemented from QAbstractItemView.moveCursor().

### Movement QListView.movement (self)

### QListView.paintEvent (self, QPaintEvent)

Reimplemented from QWidget.paintEvent().

### QRect QListView.rectForIndex (self, QModelIndex)

Returns the rectangle of the item at position index in the model. The rectangle is in contents coordinates.

See also visualRect().

### QListView.reset (self)

### QListView.resizeEvent (self, QResizeEvent)

Reimplemented from QWidget.resizeEvent().

### ResizeMode QListView.resizeMode (self)

### QListView.rowsAboutToBeRemoved (self, QModelIndex, int, int)

Reimplemented from QAbstractItemView.rowsAboutToBeRemoved().

### QListView.rowsInserted (self, QModelIndex, int, int)

Reimplemented from QAbstractItemView.rowsInserted().

### QListView.scrollContentsBy (self, int, int)

### QListView.scrollTo (self, QModelIndex, QAbstractItemView.ScrollHint hint = QAbstractItemView.EnsureVisible)

Reimplemented from QAbstractItemView.scrollTo().

### list-of-QModelIndex QListView.selectedIndexes (self)

Reimplemented from QAbstractItemView.selectedIndexes().

### QListView.selectionChanged (self, QItemSelection, QItemSelection)

Reimplemented from QAbstractItemView.selectionChanged().

### QListView.setBatchSize (self, int)

### QListView.setFlow (self, Flow)

### QListView.setGridSize (self, QSize)

### QListView.setLayoutMode (self, LayoutMode)

### QListView.setModelColumn (self, int)

### QListView.setMovement (self, Movement)

### QListView.setPositionForIndex (self, QPoint, QModelIndex)

Sets the contents position of the item at index in the model to the given position. If the list view's movement mode is Static or its view mode is ListView, this function will have no effect.

This function was introduced in Qt 4.1.

### QListView.setResizeMode (self, ResizeMode)

### QListView.setRootIndex (self, QModelIndex)

### QListView.setRowHidden (self, int, bool)

If hide is true, the given row will be hidden; otherwise the row will be shown.

See also isRowHidden().

### QListView.setSelection (self, QRect, QItemSelectionModel.SelectionFlags)

Reimplemented from QAbstractItemView.setSelection().

### QListView.setSelectionRectVisible (self, bool)

### QListView.setSpacing (self, int)

### QListView.setUniformItemSizes (self, bool)

### QListView.setViewMode (self, ViewMode)

### QListView.setWordWrap (self, bool)

### QListView.setWrapping (self, bool)

### int QListView.spacing (self)

### QListView.startDrag (self, Qt.DropActions)

Reimplemented from QAbstractItemView.startDrag().

### QListView.timerEvent (self, QTimerEvent)

Reimplemented from QObject.timerEvent().

### bool QListView.uniformItemSizes (self)

### QListView.updateGeometries (self)

Reimplemented from QAbstractItemView.updateGeometries().

### int QListView.verticalOffset (self)

Reimplemented from QAbstractItemView.verticalOffset().

### ViewMode QListView.viewMode (self)

### QStyleOptionViewItem QListView.viewOptions (self)

Reimplemented from QAbstractItemView.viewOptions().

### QRect QListView.visualRect (self, QModelIndex)

Reimplemented from QAbstractItemView.visualRect().

### QRegion QListView.visualRegionForSelection (self, QItemSelection)

Reimplemented from QAbstractItemView.visualRegionForSelection().

### bool QListView.wordWrap (self)

## Qt Signal Documentation

### void indexesMoved (const QModelIndexList&)

This is the default overload of this signal.

This signal is emitted when the specified indexes are moved in the view.

This function was introduced in Qt 4.2.