QListView 类

The QListView 类为模型提供列表 (或图标) 视图。 更多...

头: #include <QListView>
继承: QAbstractItemView
继承者: QHelpIndexWidget , QListWidget ,和 QUndoView

公共类型

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

特性

公共函数

QListView (QWidget * parent = 0)
~QListView ()
int batchSize () const
void clearPropertyFlags ()
Flow flow () const
QSize gridSize () const
bool isRowHidden (int row ) const
bool isSelectionRectVisible () const
bool isWrapping () const
LayoutMode layoutMode () const
int modelColumn () const
Movement movement () const
ResizeMode resizeMode () const
void setBatchSize (int batchSize )
void setFlow (Flow flow )
void setGridSize (const QSize & size )
void setLayoutMode (LayoutMode mode )
void setModelColumn (int column )
void setMovement (Movement movement )
void setResizeMode (ResizeMode mode )
void setRowHidden (int row , bool hide )
void setSelectionRectVisible (bool show )
void setSpacing (int space )
void setUniformItemSizes (bool enable )
void setViewMode (ViewMode mode )
void setWordWrap (bool on )
void setWrapping (bool enable )
int spacing () const
bool uniformItemSizes () const
ViewMode viewMode () const
bool wordWrap () const

重实现公共函数

virtual QModelIndex indexAt (const QPoint & p ) const
virtual void scrollTo (const QModelIndex & index , ScrollHint hint = EnsureVisible)
virtual QRect visualRect (const QModelIndex & index ) const

信号

void indexesMoved (const QModelIndexList & indexes )

保护函数

QRect rectForIndex (const QModelIndex & index ) const
void setPositionForIndex (const QPoint & position , const QModelIndex & index )

重实现保护函数

virtual void currentChanged (const QModelIndex & current , const QModelIndex & previous )
virtual void dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight )
virtual void dragLeaveEvent (QDragLeaveEvent * e )
virtual void dragMoveEvent (QDragMoveEvent * e )
virtual void dropEvent (QDropEvent * e )
virtual bool event (QEvent * e )
virtual int horizontalOffset () const
virtual bool isIndexHidden (const QModelIndex & index ) const
virtual void mouseMoveEvent (QMouseEvent * e )
virtual void mouseReleaseEvent (QMouseEvent * e )
virtual QModelIndex moveCursor (CursorAction cursorAction , Qt::KeyboardModifiers modifiers )
virtual void paintEvent (QPaintEvent * e )
virtual void resizeEvent (QResizeEvent * e )
virtual void rowsAboutToBeRemoved (const QModelIndex & parent , int start , int end )
virtual void rowsInserted (const QModelIndex & parent , int start , int end )
virtual QModelIndexList selectedIndexes () const
virtual void selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )
virtual void setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags 命令 )
virtual void startDrag (Qt::DropActions supportedActions )
virtual void timerEvent (QTimerEvent * e )
virtual void updateGeometries ()
virtual int verticalOffset () const
virtual QStyleOptionViewItem viewOptions () const
virtual QRegion visualRegionForSelection (const QItemSelection & selection ) const

额外继承成员

详细描述

The QListView 类为模型提供列表 (或图标) 视图。

A QListView 以简单非分层列表 (或图标的集合) 形式呈现模型中存储的项。此类用于提供列表和图标视图,以前提供是通过 QListBox and QIconView 类,但使用由 Qt 模型/视图体系结构提供的方式更灵活。

The QListView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .

此视图不显示水平或垂直标题;要显示具有水平标题的项列表,使用 QTreeView 代替。

QListView 实现接口的定义通过 QAbstractItemView 类以允许它显示提供数据,通过模型派生自 QAbstractItemModel 类。

可以使用 2 种视图模式之一显示列表视图中的项:按 ListMode ,项以简单列表形式显示;按 IconMode ,列表视图接受的形式为 图标视图 其中项按图标显示 (像:文件管理器中的文件)。默认情况下,列表视图按 ListMode 。要改变视图模式,使用 setViewMode () 函数,和要确定当前视图模式,使用 viewMode ().

这些视图项的布置方向指定通过 flow () 对于列表视图。项可能固定在到位,或允许移动,从属视图 movement () 状态。

若模型中的项无法完全按流方向布置,可以在视图 Widget 边界处换行它们;这取决于 isWrapping ()。此特性很有用,当按图标视图表示项时。

The resizeMode () 和 layoutMode () 支配如何及何时布置项。项间隔按照其 spacing (),且可以存在于名义大小栅格中指定通过 gridSize ()。项可以渲染为大图标 (或小图标) 从属其 iconSize ().

Screenshot of a Windows XP style list view Screenshot of a Macintosh 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.

改善性能

赋予正处理数据的有关视图提示是可能的,为改善其性能当显示大量项时。对于旨在显示带有相等大小的项的视图而言,可以采纳的一种方式是设置 uniformItemSizes 特性为 true。

另请参阅 视图类 , QTreeView , QTableView ,和 QListWidget .

成员类型文档编制

enum QListView:: Flow

常量 描述
QListView::LeftToRight 0 项从左到右布置在视图中。
QListView::TopToBottom 1 项从上到下布置在视图中。

enum QListView:: LayoutMode

常量 描述
QListView::SinglePass 0 一次性布置所有项。
QListView::Batched 1 项的布置是每批 batchSize 项。

另请参阅 batchSize .

enum QListView:: Movement

常量 描述
QListView::Static 0 用户无法移动项。
QListView::Free 1 用户可以自由移动项。
QListView::Snap 2 项捕捉到指定栅格当移动时;见 setGridSize ().

enum QListView:: ResizeMode

常量 描述
QListView::Fixed 0 仅首次布置项时展示视图。
QListView::Adjust 1 每当重置布置项视图大小时。

enum QListView:: ViewMode

常量 描述
QListView::ListMode 0 布置项使用 TopToBottom 流,采用 Small 尺寸和 Static 移动
QListView::IconMode 1 布置项使用 LeftToRight 流,采用 Large 尺寸和 Free 移动

特性文档编制

batchSize : int

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

默认值为 100。

该特性在 Qt 4.2 引入。

访问函数:

int batchSize () const
void setBatchSize (int batchSize )

flow : Flow

此特性保持项布局应流化的方向。

若此特性为 LeftToRight ,从左到右布置项。若 isWrapping property is true, the layout will wrap when it reaches the right side of the visible area. If this property is TopToBottom ,项将从可见区域顶部开始布置,到达底部时换行。

设置此特性将导致再次布置项,当视图可见时。

默认情况下,此特性被设为 TopToBottom .

访问函数:

Flow flow () const
void setFlow (Flow flow )

另请参阅 viewMode .

gridSize : QSize

This property holds the size of the layout grid.

此特性是在其中布置项的栅格的大小。默认大小为空,意味着没有栅格且布局也不在栅格中完成。将此特性设为非空大小,切换栅格布局为开 (当栅格布局生效 spacing 特性被忽略)。

设置此特性将导致再次布置项,当视图可见时。

访问函数:

QSize gridSize () const
void setGridSize (const QSize & size )

另请参阅 viewMode .

isWrapping : bool

此特性保持项布局是否应换行。

此特性保持是否应换行布局,当可见区域没有更多空间时。布局换行点从属 flow 特性。

设置此特性将导致再次布置项,当视图可见时。

默认情况下,此特性为 false。

访问函数:

bool isWrapping () const
void setWrapping (bool enable )

另请参阅 viewMode .

layoutMode : LayoutMode

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

此特性保持项的布局模式。当模式为 SinglePass (默认),一次性布置所有项。当模式为 Batched ,项的布置是每批 batchSize 项,当处理事件时。这使马上查看可见项并与之交互成为可能,当在布置其余项时。

访问函数:

LayoutMode layoutMode () const
void setLayoutMode (LayoutMode mode )

另请参阅 viewMode .

modelColumn : int

此特性保持可见模型列。

默认情况下,此特性包含 0,指示将展示模型中的第 1 列。

访问函数:

int modelColumn () const
void setModelColumn (int column )

movement : Movement

此特性保持项是否能自由移动、捕捉到栅格、或根本无法移动。

此特性确定用户可以在视图中如何移动项。 Static 意味着用户无法移动项。 Free 意味着用户可以将项拖放到视图中的任意位置。 Snap 意味着用户可以拖放项,但只能定位到名义栅格表示通过 gridSize 特性。

设置此特性将导致再次布置项,当视图可见时。

默认情况下,此特性被设为 Static .

访问函数:

Movement movement () const
void setMovement (Movement movement )

另请参阅 gridSize , resizeMode ,和 viewMode .

resizeMode : ResizeMode

此特性保持是否再次布置项,当重置视图大小时。

若此特性为 Adjust ,将再次布置项,当重置视图大小时。若值为 Fixed ,不布置项当重置视图大小时。

默认情况下,此特性被设为 Fixed .

访问函数:

ResizeMode resizeMode () const
void setResizeMode (ResizeMode mode )

另请参阅 movement , gridSize ,和 viewMode .

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.

注意: 选定矩形才可见,若选择模式为可以选择多项;即:不绘制选定矩形若选择模式为 QAbstractItemView::SingleSelection .

默认情况下,此特性为 false。

该特性在 Qt 4.3 引入。

访问函数:

bool isSelectionRectVisible () const
void setSelectionRectVisible (bool show )

spacing : int

This property holds the space around the items in the layout.

此特性是围绕布局中项填充的空空间大小。

设置此特性将导致再次布置项,当视图可见时。

默认情况下,此特性包含 0 值。

访问函数:

int spacing () const
void setSpacing (int space )

另请参阅 viewMode .

uniformItemSizes : bool

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

才应将此特性设为 true 若要保证视图中的所有项拥有相同大小。这使视图能够出于性能目的做一些优化。

默认情况下,此特性为 false。

该特性在 Qt 4.1 引入。

访问函数:

bool uniformItemSizes () const
void setUniformItemSizes (bool enable )

viewMode : ViewMode

This property holds the view mode of the QListView.

此特性将其它未设置特性,更改成与设置视图模式一致。 QListView 特定特性 (已设置的) 不改变,除非 clearPropertyFlags () 被调用。

设置视图模式将基于选中移动启用 (或禁用) 拖放。对于 ListMode ,默认移动为 Static (禁用拖放);对于 IconMode ,默认移动为 Free (启用拖放)。

访问函数:

ViewMode viewMode () const
void setViewMode (ViewMode mode )

另请参阅 isWrapping , spacing , gridSize , flow , movement ,和 resizeMode .

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.

请注意,即使启用了换行,也不会为文本腾出空间而展开单元格。无法展示的文本将打印省略号,根据视图的 textElideMode .

该特性在 Qt 4.2 引入。

访问函数:

bool wordWrap () const
void setWordWrap (bool on )

成员函数文档编制

QListView:: QListView ( QWidget * parent = 0)

创建新的 QListView 采用给定 parent 以查看模型。使用 setModel () 来设置模型。

QListView:: ~QListView ()

销毁视图。

void QListView:: clearPropertyFlags ()

清零 QListView 特定特性标志。见 viewMode .

特性继承自 QAbstractItemView 未被特性标志涵盖。具体来说, dragEnabled and acceptsDrops 的计算是通过 QListView 当调用 setMovement () 或 setViewMode ().

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

重实现自 QAbstractItemView::currentChanged ().

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

重实现自 QAbstractItemView::dataChanged ().

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

重实现自 QWidget::dragLeaveEvent ().

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

重实现自 QWidget::dragMoveEvent ().

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

重实现自 QWidget::dropEvent ().

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

重实现自 QObject::event ().

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

重实现自 QAbstractItemView::horizontalOffset ().

[虚拟] QModelIndex QListView:: indexAt (const QPoint & p ) const

重实现自 QAbstractItemView::indexAt ().

[signal] void QListView:: indexesMoved (const QModelIndexList & indexes )

此信号被发射当指定 indexes 在视图中被移动。

该函数在 Qt 4.2 引入。

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

重实现自 QAbstractItemView::isIndexHidden ().

bool QListView:: isRowHidden ( int row ) const

返回 true 若 row is hidden; otherwise returns false.

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

重实现自 QWidget::mouseMoveEvent ().

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

重实现自 QWidget::mouseReleaseEvent ().

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

重实现自 QAbstractItemView::moveCursor ().

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

重实现自 QWidget::paintEvent ().

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

返回项矩形在位置 index 在模型中。矩形位于内容坐标中。

另请参阅 visualRect ().

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

重实现自 QWidget::resizeEvent ().

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

重实现自 QAbstractItemView::rowsAboutToBeRemoved ().

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

重实现自 QAbstractItemView::rowsInserted ().

[虚拟] void QListView:: scrollTo (const QModelIndex & index , ScrollHint hint = EnsureVisible)

重实现自 QAbstractItemView::scrollTo ().

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

重实现自 QAbstractItemView::selectedIndexes ().

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

重实现自 QAbstractItemView::selectionChanged ().

[protected] void QListView:: setPositionForIndex (const QPoint & position , const QModelIndex & index )

设置项内容位置在 index 在模型中到给定 position 。若列表视图的移动模式为 Static 或其视图模式为 ListView ,此函数没有效果。

该函数在 Qt 4.1 引入。

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

hide 为 True,给定 row 将隐藏;否则 row 将展示。

另请参阅 isRowHidden ().

[virtual protected] void QListView:: setSelection (const QRect & rect , QItemSelectionModel::SelectionFlags 命令 )

重实现自 QAbstractItemView::setSelection ().

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

重实现自 QAbstractItemView::startDrag ().

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

重实现自 QObject::timerEvent ().

[virtual protected] void QListView:: updateGeometries ()

重实现自 QAbstractItemView::updateGeometries ().

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

重实现自 QAbstractItemView::verticalOffset ().

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

重实现自 QAbstractItemView::viewOptions ().

[虚拟] QRect QListView:: visualRect (const QModelIndex & index ) const

重实现自 QAbstractItemView::visualRect ().

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

重实现自 QAbstractItemView::visualRegionForSelection ().

从 4.7 起,返回区域仅包含 (或包括在) 视口相交矩形。