QListView 类为模型提供列表或图标视图。 更多...
头: | #include <QListView> |
qmake: | QT += widgets |
继承: | QAbstractItemView |
继承者: |
enum | Flow { LeftToRight, TopToBottom } |
enum | LayoutMode { SinglePass, Batched } |
enum | Movement { Static, Free, Snap } |
enum | ResizeMode { Fixed, Adjust } |
enum | ViewMode { ListMode, IconMode } |
|
|
QListView (QWidget * parent = Q_NULLPTR) | |
~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 , const QVector<int> & roles = QVector<int> ()) |
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 QSize | viewportSizeHint () const |
virtual QRegion | visualRegionForSelection (const QItemSelection & selection ) const |
virtual void | wheelEvent (QWheelEvent * e ) |
QListView 类为模型提供列表或图标视图。
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
类,但使用由 Qt 模型/视图体系结构提供的方式更灵活。
QListView 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .
此视图不显示水平或垂直标题;要显示具有水平标题的项列表,使用 QTreeView 代替。
QListView implements the interfaces defined by the QAbstractItemView 类以允许它显示提供数据,通过模型派生自 QAbstractItemModel 类。
可以使用 2 种视图模式之一显示列表视图中的项:按 ListMode ,项目以简单列表形式显示;按 IconMode ,列表视图接受的形式为 图标视图 其中项按图标显示 (像:文件管理器中的文件)。默认情况下,列表视图按 ListMode 。要改变视图模式,使用 setViewMode () 函数,和要确定当前视图模式,使用 viewMode ().
这些视图项的布置方向指定通过 flow () 对于列表视图。项可能固定在到位,或允许移动,从属视图 movement () 状态。
若模型中的项无法完全按流方向布置,可以在视图 Widget 边界处换行它们;这取决于 isWrapping ()。此特性很有用,当按图标视图表示项时。
resizeMode () 和 layoutMode () 支配项的布局方式和时间。项间隔按照其 spacing (),且可以存在于名义大小栅格中指定通过 gridSize ()。项可以渲染为大图标 (或小图标) 从属其 iconSize ().
赋予正处理数据的有关视图提示是可能的,为改善其性能当显示大量项时。对于旨在显示带有相等大小的项的视图而言,可以采纳的一种方式是设置 uniformItemSizes 特性到 true。
另请参阅 视图类 , 项视图拼图范例 , QTreeView , QTableView ,和 QListWidget .
常量 | 值 | 描述 |
---|---|---|
QListView::LeftToRight
|
0
|
项从左到右布置在视图中。 |
QListView::TopToBottom
|
1
|
项从上到下布置在视图中。 |
常量 | 值 | 描述 |
---|---|---|
QListView::SinglePass
|
0
|
一次性布置所有项。 |
QListView::Batched
|
1
|
项被布置按分批的 batchSize 项。 |
另请参阅 batchSize .
常量 | 值 | 描述 |
---|---|---|
QListView::Static
|
0
|
用户无法移动项。 |
QListView::Free
|
1
|
用户可以自由移动项。 |
QListView::Snap
|
2
|
项捕捉到指定栅格当移动时;见 setGridSize (). |
常量 | 值 | 描述 |
---|---|---|
QListView::Fixed
|
0
|
仅首次布置项时展示视图。 |
QListView::Adjust
|
1
|
每次布置项都重置视图大小。 |
常量 | 值 | 描述 |
---|---|---|
QListView::ListMode
|
0
|
布置项使用 TopToBottom 流,采用 Small 尺寸和 Static 移动 |
QListView::IconMode
|
1
|
布置项使用 LeftToRight 流,采用 Large 尺寸和 Free 移动 |
This property holds the number of items laid out in each batch if layoutMode 被设为 Batched
默认值为 100。
该特性在 Qt 4.2 引入。
访问函数:
int | batchSize () const |
void | setBatchSize (int batchSize ) |
此特性保持项布局应流化的方向。
若此特性为
LeftToRight
, the items will be laid out left to right. If the
isWrapping
特性为
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.
设置此特性将导致项被再次布置,当视图可见时。
默认情况下,此特性被设为 TopToBottom .
访问函数:
Flow | flow () const |
void | setFlow (Flow flow ) |
另请参阅 viewMode .
此特性保持布局栅格的大小
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 特性被忽略。)
设置此特性将导致项被再次布置,当视图可见时。
访问函数:
QSize | gridSize () const |
void | setGridSize (const QSize & size ) |
另请参阅 viewMode .
此特性保持项布局是否应换行。
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 特性。
设置此特性将导致项被再次布置,当视图可见时。
默认情况下此特性为
false
.
访问函数:
bool | isWrapping () const |
void | setWrapping (bool enable ) |
另请参阅 viewMode .
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.
访问函数:
LayoutMode | layoutMode () const |
void | setLayoutMode (LayoutMode mode ) |
另请参阅 viewMode .
此特性保持可见模型列
By default, this property contains 0, indicating that the first column in the model will be shown.
访问函数:
int | modelColumn () const |
void | setModelColumn (int column ) |
此特性保持项是否可自由移动、捕捉到网格或根本无法移动。
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 特性。
设置此特性将导致项被再次布置,当视图可见时。
默认情况下,此特性被设为 Static .
访问函数:
Movement | movement () const |
void | setMovement (Movement movement ) |
另请参阅 gridSize , resizeMode ,和 viewMode .
This property holds whether the items are laid out again when the view is resized.
若此特性为 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.
默认情况下,此特性被设为 Fixed .
访问函数:
ResizeMode | resizeMode () const |
void | setResizeMode (ResizeMode mode ) |
另请参阅 movement , gridSize ,和 viewMode .
若选定矩形应该是可见的
若此特性为
true
then the selection rectangle is visible; otherwise it will be hidden.
注意: 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 .
默认情况下此特性为
false
.
该特性在 Qt 4.3 引入。
访问函数:
bool | isSelectionRectVisible () const |
void | setSelectionRectVisible (bool show ) |
此特性保持围绕布局项的空间
This property is the size of the empty space that is padded around an item in the layout.
设置此特性将导致项被再次布置,当视图可见时。
默认情况下,此特性包含 0 值。
访问函数:
int | spacing () const |
void | setSpacing (int space ) |
另请参阅 viewMode .
此特性保持列表视图中的所有项是否拥有相同大小
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.
默认情况下此特性为
false
.
该特性在 Qt 4.1 引入。
访问函数:
bool | uniformItemSizes () const |
void | setUniformItemSizes (bool enable ) |
此特性保持视图模式为 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).
访问函数:
ViewMode | viewMode () const |
void | setViewMode (ViewMode mode ) |
另请参阅 isWrapping , spacing , gridSize , flow , movement ,和 resizeMode .
此特性保持项文本的自动换行策略
若此特性为
true
then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is
false
在默认情况下。
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 .
该特性在 Qt 4.2 引入。
访问函数:
bool | wordWrap () const |
void | setWordWrap (bool on ) |
创建新的 QListView 采用给定 parent 以查看模型。使用 setModel () 来设置模型。
销毁视图。
清零 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
, const
QVector
<
int
> &
roles
= QVector<int> ())
重实现自 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 ().
[virtual]
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 ().
返回
true
若
row
被隐藏;否则返回
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 ().
[virtual]
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 引入。
若 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 ().
[virtual protected]
QSize
QListView::
viewportSizeHint
() const
重实现自 QAbstractScrollArea::viewportSizeHint ().
该函数在 Qt 5.2 引入。
[virtual]
QRect
QListView::
visualRect
(const
QModelIndex
&
index
) const
重实现自 QAbstractItemView::visualRect ().
[virtual protected]
QRegion
QListView::
visualRegionForSelection
(const
QItemSelection
&
selection
) const
重实现自 QAbstractItemView::visualRegionForSelection ().
从 4.7 起,返回区域仅包含 (或包括在) 视口相交矩形。
[virtual protected]
void
QListView::
wheelEvent
(
QWheelEvent
*
e
)
重实现自 QWidget::wheelEvent ().