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 command )
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 command )

重實現自 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 起,返迴區域僅包含 (或包括在) 視口相交矩形。