QListView Class Reference

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

  1. #include <QListView>

Inherits: QAbstractItemView.

Inherited by: QHelpIndexWidget, QListWidget, and QUndoView.

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

Screenshot of a Windows XP style list view

Screenshot of a Windows XP style list view

Screenshot of a Macintosh style table view

Screenshot of a Macintosh style table view

Screenshot of a Plastique style table view

Screenshot of a Plastique style table view

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.

Public Types

Toggle detailsenum QListView::

FlowFlow { LeftToRight , TopToBottom 1 ...} { LeftToRight , TopToBottom 1 }

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

Look up this member in the source code.

Toggle detailsenum QListView::

LayoutModeLayoutMode { SinglePass , Batched 1 ...} { SinglePass , Batched 1 }

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

Look up this member in the source code.

Toggle detailsenum QListView::

MovementMovement { Static , Free , Snap 2 ...} { Static , Free , Snap 2 }

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

Look up this member in the source code.

Toggle detailsenum QListView::

ResizeModeResizeMode { Fixed , Adjust 1 ...} { Fixed , Adjust 1 }

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

Look up this member in the source code.

Toggle detailsenum QListView::

ViewModeViewMode { ListMode , IconMode 1 ...} { ListMode , IconMode 1 }

ConstantValueDescription
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

Look up this member in the source code.

    Properties

    Toggle detailsbatchSizebatchSize : int

    This property holds the number of items laid out in each batch if layoutMode is set to Batched

    The default value is 100.

    Access functions:

    Look up this member in the source code.

    Toggle detailsflowflow : Flow

    This property holds which direction the items layout should flow.

    If this property is LeftToRight, the items will be laid out left to right. If the isWrapping property is true, the layout will wrap when it reaches the right side of the visible area. If this property is TopToBottom, the items will be laid out from the top of the visible area, wrapping when it reaches the bottom.

    Setting this property when the view is visible will cause the items to be laid out again.

    By default, this property is set to TopToBottom.

    See also viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsgridSizegridSize : QSize

    This property holds the size of the layout grid

    This property is the size of the grid in which the items are laid out. The default is an empty size which means that there is no grid and the layout is not done in a grid. Setting this property to a non-empty size switches on the grid layout. (When a grid layout is in force the spacing property is ignored.)

    Setting this property when the view is visible will cause the items to be laid out again.

    See also viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsisWrappingisWrapping : bool

    This property holds whether the items layout should wrap.

    This property holds whether the layout should wrap when there is no more space in the visible area. The point at which the layout wraps depends on the flow property.

    Setting this property when the view is visible will cause the items to be laid out again.

    By default, this property is false.

    See also viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailslayoutModelayoutMode : LayoutMode

    This property holds determines whether the layout of items should happen immediately or be delayed.

    This property holds the layout mode for the items. When the mode is SinglePass (the default), the items are laid out all in one go. When the mode is Batched, the items are laid out in batches of batchSize items, while processing events. This makes it possible to instantly view and interact with the visible items while the rest are being laid out.

    See also viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsmodelColumnmodelColumn : int

    This property holds the column in the model that is visible

    By default, this property contains 0, indicating that the first column in the model will be shown.

    Access functions:

    Look up this member in the source code.

    Toggle detailsmovementmovement : Movement

    This property holds whether the items can be moved freely, are snapped to a grid, or cannot be moved at all.

    This property determines how the user can move the items in the view. Static means that the items can't be moved the user. Free means that the user can drag and drop the items to any position in the view. Snap means that the user can drag and drop the items, but only to the positions in a notional grid signified by the gridSize property.

    Setting this property when the view is visible will cause the items to be laid out again.

    By default, this property is set to Static.

    See also gridSize, resizeMode, and viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsresizeModeresizeMode : ResizeMode

    This property holds whether the items are laid out again when the view is resized.

    If this property is Adjust, the items will be laid out again when the view is resized. If the value is Fixed, the items will not be laid out when the view is resized.

    By default, this property is set to Fixed.

    See also movement, gridSize, and viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsselectionRectVisibleselectionRectVisible : bool

    This property holds if the selection rectangle should be visible

    If this property is true then the selection rectangle is visible; otherwise it will be hidden.

    Note: The selection rectangle will only be visible if the selection mode is in a mode where more than one item can be selected; i.e., it will not draw a selection rectangle if the selection mode is QAbstractItemView::SingleSelection.

    By default, this property is false.

    Access functions:

    Look up this member in the source code.

    Toggle detailsspacingspacing : int

    This property holds the space around the items in the layout

    This property is the size of the empty space that is padded around an item in the layout.

    Setting this property when the view is visible will cause the items to be laid out again.

    By default, this property contains a value of 0.

    See also viewMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailsuniformItemSizesuniformItemSizes : bool

    This property holds whether all items in the listview have the same size

    This property should only be set to true if it is guaranteed that all items in the view have the same size. This enables the view to do some optimizations for performance purposes.

    By default, this property is false.

    Access functions:

    Look up this member in the source code.

    Toggle detailsviewModeviewMode : ViewMode

    This property holds the view mode of the QListView.

    This property will change the other unset properties to conform with the set view mode. QListView-specific properties that have already been set will not be changed, unless clearPropertyFlags() has been called.

    Setting the view mode will enable or disable drag and drop based on the selected movement. For ListMode, the default movement is Static (drag and drop disabled); for IconMode, the default movement is Free (drag and drop enabled).

    See also isWrapping, spacing, gridSize, flow, movement, and resizeMode.

    Access functions:

    Look up this member in the source code.

    Toggle detailswordWrapwordWrap : bool

    This property holds the item text word-wrapping policy

    If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is false by default.

    Please note that even if wrapping is enabled, the cell will not be expanded to make room for the text. It will print ellipsis for text that cannot be shown, according to the view's textElideMode.

    Access functions:

    Look up this member in the source code.

      Public Functions

      Toggle details QListView

      QListViewQListView ( QWidget *parent=0 ) ( QWidget *parent=0 )

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

      Look up this member in the source code.

      Toggle details QListView

      ~QListView~QListView () ()

      Destroys the view.

      Look up this member in the source code.

      Toggle details void QListView

      clearPropertyFlagsclearPropertyFlags () ()

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

      Look up this member in the source code.

      Toggle details void QListView

      currentChangedcurrentChanged ( const QModelIndex &current , const QModelIndex &previous ...) ( const QModelIndex &current , const QModelIndex &previous ) [virtual protected]

      Reimplemented from QAbstractItemView::currentChanged().

      Look up this member in the source code.

      Toggle details void QListView

      dataChangeddataChanged ( const QModelIndex &topLeft , const QModelIndex &bottomRight ...) ( const QModelIndex &topLeft , const QModelIndex &bottomRight ) [virtual protected]

      Reimplemented from QAbstractItemView::dataChanged().

      Look up this member in the source code.

      Toggle details void QListView

      dragLeaveEventdragLeaveEvent ( QDragLeaveEvent *e ) ( QDragLeaveEvent *e ) [virtual protected]

      Reimplemented from QWidget::dragLeaveEvent().

      Look up this member in the source code.

      Toggle details void QListView

      dragMoveEventdragMoveEvent ( QDragMoveEvent *e ) ( QDragMoveEvent *e ) [virtual protected]

      Reimplemented from QWidget::dragMoveEvent().

      Look up this member in the source code.

      Toggle details void QListView

      dropEventdropEvent ( QDropEvent *e ) ( QDropEvent *e ) [virtual protected]

      Reimplemented from QWidget::dropEvent().

      Look up this member in the source code.

      Toggle details bool QListView

      eventevent ( QEvent *e ) ( QEvent *e ) [virtual protected]

      Reimplemented from QObject::event().

      Look up this member in the source code.

      Toggle details int QListView

      horizontalOffsethorizontalOffset () ()const [virtual protected]

      Reimplemented from QAbstractItemView::horizontalOffset().

      Look up this member in the source code.

      Toggle details QModelIndex QListView

      indexAtindexAt ( const QPoint &p ) ( const QPoint &p )const [virtual]

      Reimplemented from QAbstractItemView::indexAt().

      Look up this member in the source code.

      Toggle details bool QListView

      isIndexHiddenisIndexHidden ( const QModelIndex &index ) ( const QModelIndex &index )const [virtual protected]

      Reimplemented from QAbstractItemView::isIndexHidden().

      Look up this member in the source code.

      Toggle details bool QListView

      isRowHiddenisRowHidden ( int row ) ( int row )const

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

      Look up this member in the source code.

      Toggle details void QListView

      mouseMoveEventmouseMoveEvent ( QMouseEvent *e ) ( QMouseEvent *e ) [virtual protected]

      Reimplemented from QWidget::mouseMoveEvent().

      Look up this member in the source code.

      Toggle details void QListView

      mouseReleaseEventmouseReleaseEvent ( QMouseEvent *e ) ( QMouseEvent *e ) [virtual protected]

      Reimplemented from QWidget::mouseReleaseEvent().

      Look up this member in the source code.

      Toggle details QModelIndex QListView

      moveCursormoveCursor ( CursorAction cursorAction , Qt::KeyboardModifiers modifiers ...) ( CursorAction cursorAction , Qt::KeyboardModifiers modifiers ) [virtual protected]

      Reimplemented from QAbstractItemView::moveCursor().

      Look up this member in the source code.

      Toggle details void QListView

      paintEventpaintEvent ( QPaintEvent *e ) ( QPaintEvent *e ) [virtual protected]

      Reimplemented from QWidget::paintEvent().

      Look up this member in the source code.

      Toggle details QRect QListView

      rectForIndexrectForIndex ( const QModelIndex &index ) ( const QModelIndex &index )const[protected]

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

      See also visualRect().

      Look up this member in the source code.

      Toggle details void QListView

      resizeEventresizeEvent ( QResizeEvent *e ) ( QResizeEvent *e ) [virtual protected]

      Reimplemented from QWidget::resizeEvent().

      Look up this member in the source code.

      Toggle details void QListView

      rowsAboutToBeRemovedrowsAboutToBeRemoved ( const QModelIndex &parent , int start , int end ...) ( const QModelIndex &parent , int start , int end ) [virtual protected]

      Look up this member in the source code.

      Toggle details void QListView

      rowsInsertedrowsInserted ( const QModelIndex &parent , int start , int end ...) ( const QModelIndex &parent , int start , int end ) [virtual protected]

      Reimplemented from QAbstractItemView::rowsInserted().

      Look up this member in the source code.

      Toggle details void QListView

      scrollToscrollTo ( const QModelIndex &index , ScrollHint hint=EnsureVisible ...) ( const QModelIndex &index , ScrollHint hint=EnsureVisible ) [virtual]

      Reimplemented from QAbstractItemView::scrollTo().

      Look up this member in the source code.

      Toggle details QModelIndexList QListView

      selectedIndexesselectedIndexes () ()const [virtual protected]

      Reimplemented from QAbstractItemView::selectedIndexes().

      Look up this member in the source code.

      Toggle details void QListView

      selectionChangedselectionChanged ( const QItemSelection &selected , const QItemSelection &deselected ...) ( const QItemSelection &selected , const QItemSelection &deselected ) [virtual protected]

      Reimplemented from QAbstractItemView::selectionChanged().

      Look up this member in the source code.

      Toggle details void QListView

      setPositionForIndexsetPositionForIndex ( const QPoint &position , const QModelIndex &index ...) ( const QPoint &position , const QModelIndex &index )[protected]

      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.

      Look up this member in the source code.

      Toggle details void QListView

      setRowHiddensetRowHidden ( int row , bool hide ) ( int row , bool hide )

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

      See also isRowHidden().

      Look up this member in the source code.

      Toggle details void QListView

      setSelectionsetSelection ( const QRect &rect , QItemSelectionModel::SelectionFlags command ...) ( const QRect &rect , QItemSelectionModel::SelectionFlags command ) [virtual protected]

      Reimplemented from QAbstractItemView::setSelection().

      Look up this member in the source code.

      Toggle details void QListView

      startDragstartDrag ( Qt::DropActions supportedActions ) ( Qt::DropActions supportedActions ) [virtual protected]

      Reimplemented from QAbstractItemView::startDrag().

      Look up this member in the source code.

      Toggle details void QListView

      timerEventtimerEvent ( QTimerEvent *e ) ( QTimerEvent *e ) [virtual protected]

      Reimplemented from QObject::timerEvent().

      Look up this member in the source code.

      Toggle details void QListView

      updateGeometriesupdateGeometries () () [virtual protected]

      Reimplemented from QAbstractItemView::updateGeometries().

      Look up this member in the source code.

      Toggle details int QListView

      verticalOffsetverticalOffset () ()const [virtual protected]

      Reimplemented from QAbstractItemView::verticalOffset().

      Look up this member in the source code.

      Toggle details QStyleOptionViewItem QListView

      viewOptionsviewOptions () ()const [virtual protected]

      Reimplemented from QAbstractItemView::viewOptions().

      Look up this member in the source code.

      Toggle details QRect QListView

      visualRectvisualRect ( const QModelIndex &index ) ( const QModelIndex &index )const [virtual]

      Reimplemented from QAbstractItemView::visualRect().

      Look up this member in the source code.

      Toggle details QRegion QListView

      visualRegionForSelectionvisualRegionForSelection ( const QItemSelection &selection ...) ( const QItemSelection &selection )const [virtual protected]

      Reimplemented from QAbstractItemView::visualRegionForSelection().

      Since 4.7, the returned region only contains rectangles intersecting (or included in) the viewport.

      Look up this member in the source code.

        Signals

        Toggle details void QListView

        indexesMovedindexesMoved ( const QModelIndexList &indexes ) ( const QModelIndexList &indexes ) [signal]

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

        Look up this member in the source code.

          Notes provided by the Qt Community

          No notes