QListView

Inheritance diagram of PySide2.QtWidgets.QListView

Inherited by: QListWidget, QUndoView, QHelpIndexWidget

Synopsis

Functions

Signals

Detailed Description

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

../../_images/windows-listview.png

A PySide2.QtWidgets.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 PySide2.QtWidgets.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 PySide2.QtWidgets.QTreeView instead.

PySide2.QtWidgets.QListView implements the interfaces defined by the PySide2.QtWidgets.QAbstractItemView class to allow it to display data provided by models derived from the PySide2.QtCore.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 PySide2.QtWidgets.QListView.setViewMode() function, and to determine the current view mode, use PySide2.QtWidgets.QListView.viewMode() .

Items in these views are laid out in the direction specified by the PySide2.QtWidgets.QListView.flow() of the list view. The items may be fixed in place, or allowed to move, depending on the view’s PySide2.QtWidgets.QListView.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 PySide2.QtWidgets.QListView.isWrapping() . This property is useful when the items are being represented by an icon view.

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

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 PySide2.QtWidgets.QListView.uniformItemSizes() property to true.

class PySide2.QtWidgets.QListView([parent=nullptr])
Parameters:parentPySide2.QtWidgets.QWidget

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

PySide2.QtWidgets.QListView.Movement
Constant Description
QListView.Static The items cannot be moved by the user.
QListView.Free The items can be moved freely by the user.
QListView.Snap The items snap to the specified grid when moved; see PySide2.QtWidgets.QListView.setGridSize() .
PySide2.QtWidgets.QListView.Flow
Constant Description
QListView.LeftToRight The items are laid out in the view from the left to the right.
QListView.TopToBottom The items are laid out in the view from the top to the bottom.
PySide2.QtWidgets.QListView.ResizeMode
Constant Description
QListView.Fixed The items will only be laid out the first time the view is shown.
QListView.Adjust The items will be laid out every time the view is resized.
PySide2.QtWidgets.QListView.LayoutMode
Constant Description
QListView.SinglePass The items are laid out all at once.
QListView.Batched The items are laid out in batches of PySide2.QtWidgets.QListView.batchSize() items.
PySide2.QtWidgets.QListView.ViewMode
Constant Description
QListView.ListMode The items are laid out using TopToBottom flow, with Small size and Static movement
QListView.IconMode The items are laid out using LeftToRight flow, with Large size and Free movement
PySide2.QtWidgets.QListView.batchSize()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QListView.clearPropertyFlags()

Clears the PySide2.QtWidgets.QListView -specific property flags. See PySide2.QtWidgets.QListView.viewMode() .

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

PySide2.QtWidgets.QListView.contentsSize()
Return type:PySide2.QtCore.QSize
PySide2.QtWidgets.QListView.flow()
Return type:PySide2.QtWidgets.QListView.Flow
PySide2.QtWidgets.QListView.gridSize()
Return type:PySide2.QtCore.QSize
PySide2.QtWidgets.QListView.indexesMoved(indexes)
Parameters:indexesPySide2.QtCore.QModelIndexList
PySide2.QtWidgets.QListView.isRowHidden(row)
Parameters:rowPySide2.QtCore.int
Return type:PySide2.QtCore.bool

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

PySide2.QtWidgets.QListView.isSelectionRectVisible()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QListView.isWrapping()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QListView.layoutMode()
Return type:PySide2.QtWidgets.QListView.LayoutMode
PySide2.QtWidgets.QListView.modelColumn()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QListView.movement()
Return type:PySide2.QtWidgets.QListView.Movement
PySide2.QtWidgets.QListView.rectForIndex(index)
Parameters:indexPySide2.QtCore.QModelIndex
Return type:PySide2.QtCore.QRect

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

See also

PySide2.QtWidgets.QListView.visualRect()

PySide2.QtWidgets.QListView.resizeContents(width, height)
Parameters:
  • widthPySide2.QtCore.int
  • heightPySide2.QtCore.int

Resize the internal contents to width and height and set the scroll bar ranges accordingly.

PySide2.QtWidgets.QListView.resizeMode()
Return type:PySide2.QtWidgets.QListView.ResizeMode
PySide2.QtWidgets.QListView.setBatchSize(batchSize)
Parameters:batchSizePySide2.QtCore.int
PySide2.QtWidgets.QListView.setFlow(flow)
Parameters:flowPySide2.QtWidgets.QListView.Flow
PySide2.QtWidgets.QListView.setGridSize(size)
Parameters:sizePySide2.QtCore.QSize
PySide2.QtWidgets.QListView.setLayoutMode(mode)
Parameters:modePySide2.QtWidgets.QListView.LayoutMode
PySide2.QtWidgets.QListView.setModelColumn(column)
Parameters:columnPySide2.QtCore.int
PySide2.QtWidgets.QListView.setMovement(movement)
Parameters:movementPySide2.QtWidgets.QListView.Movement
PySide2.QtWidgets.QListView.setPositionForIndex(position, index)
Parameters:

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.

PySide2.QtWidgets.QListView.setResizeMode(mode)
Parameters:modePySide2.QtWidgets.QListView.ResizeMode
PySide2.QtWidgets.QListView.setRowHidden(row, hide)
Parameters:
  • rowPySide2.QtCore.int
  • hidePySide2.QtCore.bool

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

PySide2.QtWidgets.QListView.setSelectionRectVisible(show)
Parameters:showPySide2.QtCore.bool
PySide2.QtWidgets.QListView.setSpacing(space)
Parameters:spacePySide2.QtCore.int
PySide2.QtWidgets.QListView.setUniformItemSizes(enable)
Parameters:enablePySide2.QtCore.bool
PySide2.QtWidgets.QListView.setViewMode(mode)
Parameters:modePySide2.QtWidgets.QListView.ViewMode
PySide2.QtWidgets.QListView.setWordWrap(on)
Parameters:onPySide2.QtCore.bool
PySide2.QtWidgets.QListView.setWrapping(enable)
Parameters:enablePySide2.QtCore.bool
PySide2.QtWidgets.QListView.spacing()
Return type:PySide2.QtCore.int
PySide2.QtWidgets.QListView.uniformItemSizes()
Return type:PySide2.QtCore.bool
PySide2.QtWidgets.QListView.viewMode()
Return type:PySide2.QtWidgets.QListView.ViewMode
PySide2.QtWidgets.QListView.wordWrap()
Return type:PySide2.QtCore.bool