Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QListView Class

TheQListView class provides a list or icon view onto a model.More...

Header:#include <QListView>
Inherits:QAbstractItemView
Inherited By:

QHelpIndexWidget,QListWidget, andQUndoView

Public Types

enumFlow { LeftToRight, TopToBottom }
enumLayoutMode { SinglePass, Batched }
enumMovement { Static, Free, Snap }
enumResizeMode { Fixed, Adjust }
enumViewMode { ListMode, IconMode }

Properties

Public Functions

QListView(QWidget * parent = 0)
~QListView()
intbatchSize() const
voidclearPropertyFlags()
Flowflow() const
QSizegridSize() const
boolisRowHidden(int row) const
boolisSelectionRectVisible() const
boolisWrapping() const
LayoutModelayoutMode() const
intmodelColumn() const
Movementmovement() const
ResizeModeresizeMode() const
voidsetBatchSize(int batchSize)
voidsetFlow(Flow flow)
voidsetGridSize(const QSize & size)
voidsetLayoutMode(LayoutMode mode)
voidsetModelColumn(int column)
voidsetMovement(Movement movement)
voidsetResizeMode(ResizeMode mode)
voidsetRowHidden(int row, bool hide)
voidsetSelectionRectVisible(bool show)
voidsetSpacing(int space)
voidsetUniformItemSizes(bool enable)
voidsetViewMode(ViewMode mode)
voidsetWordWrap(bool on)
voidsetWrapping(bool enable)
intspacing() const
booluniformItemSizes() const
ViewModeviewMode() const
boolwordWrap() const

Reimplemented Public Functions

virtual QModelIndexindexAt(const QPoint & p) const
virtual voidscrollTo(const QModelIndex & index, ScrollHint hint = EnsureVisible)
virtual QRectvisualRect(const QModelIndex & index) const

Signals

voidindexesMoved(const QModelIndexList & indexes)

Protected Functions

QRectrectForIndex(const QModelIndex & index) const
voidsetPositionForIndex(const QPoint & position, const QModelIndex & index)

Reimplemented Protected Functions

virtual voidcurrentChanged(const QModelIndex & current, const QModelIndex & previous)
virtual voiddataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)
virtual voiddragLeaveEvent(QDragLeaveEvent * e)
virtual voiddragMoveEvent(QDragMoveEvent * e)
virtual voiddropEvent(QDropEvent * e)
virtual boolevent(QEvent * e)
virtual inthorizontalOffset() const
virtual boolisIndexHidden(const QModelIndex & index) const
virtual voidmouseMoveEvent(QMouseEvent * e)
virtual voidmouseReleaseEvent(QMouseEvent * e)
virtual QModelIndexmoveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
virtual voidpaintEvent(QPaintEvent * e)
virtual voidresizeEvent(QResizeEvent * e)
virtual voidrowsAboutToBeRemoved(const QModelIndex & parent, int start, int end)
virtual voidrowsInserted(const QModelIndex & parent, int start, int end)
virtual QModelIndexListselectedIndexes() const
virtual voidselectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
virtual voidsetSelection(const QRect & rect, QItemSelectionModel::SelectionFlags command)
virtual voidstartDrag(Qt::DropActions supportedActions)
virtual voidtimerEvent(QTimerEvent * e)
virtual voidupdateGeometries()
virtual intverticalOffset() const
virtual QStyleOptionViewItemviewOptions() const
virtual QRegionvisualRegionForSelection(const QItemSelection & selection) const

Additional Inherited Members

Detailed Description

TheQListView class provides a list or icon view onto a model.

AQListView 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 theQListBox andQIconView classes, but using the more flexible approach provided by Qt's model/view architecture.

TheQListView class is one of theModel/View Classes and is part of Qt'smodel/view framework.

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

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

Items in a list view can be displayed using one of two view modes: InListMode, the items are displayed in the form of a simple list; inIconMode, the list view takes the form of anicon view in which the items are displayed with icons like files in a file manager. By default, the list view is inListMode. To change the view mode, use thesetViewMode() function, and to determine the current view mode, useviewMode().

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

TheresizeMode() andlayoutMode() govern how and when the items are laid out. Items are spaced according to theirspacing(), and can exist within a notional grid of size specified bygridSize(). The items can be rendered as large or small icons depending on theiriconSize().

Screenshot of a Windows XP style list viewScreenshot of a Macintosh style table viewScreenshot of a Plastique style table view
AWindows XP style list view.AMacintosh style list view.APlastique 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 theuniformItemSizes property to true.

See alsoView Classes,QTreeView,QTableView, andQListWidget.

Member Type Documentation

enum QListView::Flow

ConstantValueDescription
QListView::LeftToRight0The items are laid out in the view from the left to the right.
QListView::TopToBottom1The items are laid out in the view from the top to the bottom.

enum QListView::LayoutMode

ConstantValueDescription
QListView::SinglePass0The items are laid out all at once.
QListView::Batched1The items are laid out in batches ofbatchSize items.

See alsobatchSize.

enum QListView::Movement

ConstantValueDescription
QListView::Static0The items cannot be moved by the user.
QListView::Free1The items can be moved freely by the user.
QListView::Snap2The items snap to the specified grid when moved; seesetGridSize().

enum QListView::ResizeMode

ConstantValueDescription
QListView::Fixed0The items will only be laid out the first time the view is shown.
QListView::Adjust1The items will be laid out every time the view is resized.

enum QListView::ViewMode

ConstantValueDescription
QListView::ListMode0The items are laid out usingTopToBottom flow, with Small size and Static movement
QListView::IconMode1The items are laid out usingLeftToRight flow, with Large size and Free movement

Property Documentation

batchSize :int

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

The default value is 100.

This property was introduced in Qt 4.2.

Access functions:

intbatchSize() const
voidsetBatchSize(int batchSize)

flow :Flow

This property holds which direction the items layout should flow.

If this property isLeftToRight, the items will be laid out left to right. If theisWrapping property is true, the layout will wrap when it reaches the right side of the visible area. If this property isTopToBottom, 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 toTopToBottom.

Access functions:

Flowflow() const
voidsetFlow(Flow flow)

See alsoviewMode.

gridSize :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 thespacing property is ignored.)

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

Access functions:

QSizegridSize() const
voidsetGridSize(const QSize & size)

See alsoviewMode.

isWrapping :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 theflow property.

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

By default, this property is false.

Access functions:

boolisWrapping() const
voidsetWrapping(bool enable)

See alsoviewMode.

layoutMode :LayoutMode

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

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

Access functions:

LayoutModelayoutMode() const
voidsetLayoutMode(LayoutMode mode)

See alsoviewMode.

modelColumn :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:

intmodelColumn() const
voidsetModelColumn(int column)

movement :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 thegridSize property.

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

By default, this property is set toStatic.

Access functions:

Movementmovement() const
voidsetMovement(Movement movement)

See alsogridSize,resizeMode, andviewMode.

resizeMode :ResizeMode

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

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

By default, this property is set toFixed.

Access functions:

ResizeModeresizeMode() const
voidsetResizeMode(ResizeMode mode)

See alsomovement,gridSize, andviewMode.

selectionRectVisible :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 isQAbstractItemView::SingleSelection.

By default, this property is false.

This property was introduced in Qt 4.3.

Access functions:

boolisSelectionRectVisible() const
voidsetSelectionRectVisible(bool show)

spacing :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.

Access functions:

intspacing() const
voidsetSpacing(int space)

See alsoviewMode.

uniformItemSizes :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.

This property was introduced in Qt 4.1.

Access functions:

booluniformItemSizes() const
voidsetUniformItemSizes(bool enable)

viewMode :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, unlessclearPropertyFlags() has been called.

Setting the view mode will enable or disable drag and drop based on the selected movement. ForListMode, the default movement isStatic (drag and drop disabled); forIconMode, the default movement isFree (drag and drop enabled).

Access functions:

ViewModeviewMode() const
voidsetViewMode(ViewMode mode)

See alsoisWrapping,spacing,gridSize,flow,movement, andresizeMode.

wordWrap :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'stextElideMode.

This property was introduced in Qt 4.2.

Access functions:

boolwordWrap() const
voidsetWordWrap(bool on)

Member Function Documentation

QListView::QListView(QWidget * parent = 0)

Creates a newQListView with the givenparent to view a model. UsesetModel() to set the model.

QListView::~QListView()

Destroys the view.

void QListView::clearPropertyFlags()

Clears theQListView-specific property flags. SeeviewMode.

Properties inherited fromQAbstractItemView are not covered by the property flags. Specifically,dragEnabled andacceptsDrops are computed byQListView when callingsetMovement() orsetViewMode().

[virtual protected]void QListView::currentChanged(constQModelIndex & current, constQModelIndex & previous)

Reimplemented fromQAbstractItemView::currentChanged().

[virtual protected]void QListView::dataChanged(constQModelIndex & topLeft, constQModelIndex & bottomRight)

Reimplemented fromQAbstractItemView::dataChanged().

[virtual protected]void QListView::dragLeaveEvent(QDragLeaveEvent * e)

Reimplemented fromQWidget::dragLeaveEvent().

[virtual protected]void QListView::dragMoveEvent(QDragMoveEvent * e)

Reimplemented fromQWidget::dragMoveEvent().

[virtual protected]void QListView::dropEvent(QDropEvent * e)

Reimplemented fromQWidget::dropEvent().

[virtual protected]bool QListView::event(QEvent * e)

Reimplemented fromQObject::event().

[virtual protected]int QListView::horizontalOffset() const

Reimplemented fromQAbstractItemView::horizontalOffset().

[virtual]QModelIndex QListView::indexAt(constQPoint & p) const

Reimplemented fromQAbstractItemView::indexAt().

[signal]void QListView::indexesMoved(constQModelIndexList & indexes)

This signal is emitted when the specifiedindexes are moved in the view.

This function was introduced in Qt 4.2.

[virtual protected]bool QListView::isIndexHidden(constQModelIndex & index) const

Reimplemented fromQAbstractItemView::isIndexHidden().

bool QListView::isRowHidden(int row) const

Returns true if therow is hidden; otherwise returns false.

[virtual protected]void QListView::mouseMoveEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseMoveEvent().

[virtual protected]void QListView::mouseReleaseEvent(QMouseEvent * e)

Reimplemented fromQWidget::mouseReleaseEvent().

[virtual protected]QModelIndex QListView::moveCursor(CursorAction cursorAction,Qt::KeyboardModifiers modifiers)

Reimplemented fromQAbstractItemView::moveCursor().

[virtual protected]void QListView::paintEvent(QPaintEvent * e)

Reimplemented fromQWidget::paintEvent().

[protected]QRect QListView::rectForIndex(constQModelIndex & index) const

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

See alsovisualRect().

[virtual protected]void QListView::resizeEvent(QResizeEvent * e)

Reimplemented fromQWidget::resizeEvent().

[virtual protected]void QListView::rowsAboutToBeRemoved(constQModelIndex & parent,int start,int end)

Reimplemented fromQAbstractItemView::rowsAboutToBeRemoved().

[virtual protected]void QListView::rowsInserted(constQModelIndex & parent,int start,int end)

Reimplemented fromQAbstractItemView::rowsInserted().

[virtual]void QListView::scrollTo(constQModelIndex & index,ScrollHint hint = EnsureVisible)

Reimplemented fromQAbstractItemView::scrollTo().

[virtual protected]QModelIndexList QListView::selectedIndexes() const

Reimplemented fromQAbstractItemView::selectedIndexes().

[virtual protected]void QListView::selectionChanged(constQItemSelection & selected, constQItemSelection & deselected)

Reimplemented fromQAbstractItemView::selectionChanged().

[protected]void QListView::setPositionForIndex(constQPoint & position, constQModelIndex & index)

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

This function was introduced in Qt 4.1.

void QListView::setRowHidden(int row,bool hide)

Ifhide is true, the givenrow will be hidden; otherwise therow will be shown.

See alsoisRowHidden().

[virtual protected]void QListView::setSelection(constQRect & rect,QItemSelectionModel::SelectionFlags command)

Reimplemented fromQAbstractItemView::setSelection().

[virtual protected]void QListView::startDrag(Qt::DropActions supportedActions)

Reimplemented fromQAbstractItemView::startDrag().

[virtual protected]void QListView::timerEvent(QTimerEvent * e)

Reimplemented fromQObject::timerEvent().

[virtual protected]void QListView::updateGeometries()

Reimplemented fromQAbstractItemView::updateGeometries().

[virtual protected]int QListView::verticalOffset() const

Reimplemented fromQAbstractItemView::verticalOffset().

[virtual protected]QStyleOptionViewItem QListView::viewOptions() const

Reimplemented fromQAbstractItemView::viewOptions().

[virtual]QRect QListView::visualRect(constQModelIndex & index) const

Reimplemented fromQAbstractItemView::visualRect().

[virtual protected]QRegion QListView::visualRegionForSelection(constQItemSelection & selection) const

Reimplemented fromQAbstractItemView::visualRegionForSelection().

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

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp