Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qlistview.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLISTVIEW_H
5#define QLISTVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractitemview.h>
9
11
13
15
16class Q_WIDGETS_EXPORT QListView : public QAbstractItemView
17{
19 Q_PROPERTY(Movement movement READ movement WRITE setMovement)
20 Q_PROPERTY(Flow flow READ flow WRITE setFlow)
21 Q_PROPERTY(bool isWrapping READ isWrapping WRITE setWrapping)
22 Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
23 Q_PROPERTY(LayoutMode layoutMode READ layoutMode WRITE setLayoutMode)
24 Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
25 Q_PROPERTY(QSize gridSize READ gridSize WRITE setGridSize)
26 Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
27 Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn)
28 Q_PROPERTY(bool uniformItemSizes READ uniformItemSizes WRITE setUniformItemSizes)
29 Q_PROPERTY(int batchSize READ batchSize WRITE setBatchSize)
30 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
31 Q_PROPERTY(bool selectionRectVisible READ isSelectionRectVisible WRITE setSelectionRectVisible)
32 Q_PROPERTY(Qt::Alignment itemAlignment READ itemAlignment WRITE setItemAlignment)
33
34public:
35 enum Movement { Static, Free, Snap };
36 Q_ENUM(Movement)
37 enum Flow { LeftToRight, TopToBottom };
38 Q_ENUM(Flow)
39 enum ResizeMode { Fixed, Adjust };
40 Q_ENUM(ResizeMode)
41 enum LayoutMode { SinglePass, Batched };
42 Q_ENUM(LayoutMode)
43 enum ViewMode { ListMode, IconMode };
44 Q_ENUM(ViewMode)
45
46 explicit QListView(QWidget *parent = nullptr);
47 ~QListView();
48
49 void setMovement(Movement movement);
50 Movement movement() const;
51
52 void setFlow(Flow flow);
53 Flow flow() const;
54
55 void setWrapping(bool enable);
56 bool isWrapping() const;
57
58 void setResizeMode(ResizeMode mode);
59 ResizeMode resizeMode() const;
60
61 void setLayoutMode(LayoutMode mode);
62 LayoutMode layoutMode() const;
63
64 void setSpacing(int space);
65 int spacing() const;
66
67 void setBatchSize(int batchSize);
68 int batchSize() const;
69
70 void setGridSize(const QSize &size);
71 QSize gridSize() const;
72
73 void setViewMode(ViewMode mode);
74 ViewMode viewMode() const;
75
76 void clearPropertyFlags();
77
78 bool isRowHidden(int row) const;
79 void setRowHidden(int row, bool hide);
80
81 void setModelColumn(int column);
82 int modelColumn() const;
83
84 void setUniformItemSizes(bool enable);
85 bool uniformItemSizes() const;
86
87 void setWordWrap(bool on);
88 bool wordWrap() const;
89
90 void setSelectionRectVisible(bool show);
91 bool isSelectionRectVisible() const;
92
93 void setItemAlignment(Qt::Alignment alignment);
94 Qt::Alignment itemAlignment() const;
95
96 QRect visualRect(const QModelIndex &index) const override;
97 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
98 QModelIndex indexAt(const QPoint &p) const override;
99
100 void doItemsLayout() override;
101 void reset() override;
102 void setRootIndex(const QModelIndex &index) override;
103
105 void indexesMoved(const QModelIndexList &indexes);
106
107protected:
109
110 bool event(QEvent *e) override;
111
112 void scrollContentsBy(int dx, int dy) override;
113
114 void resizeContents(int width, int height);
115 QSize contentsSize() const;
116
117 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
118 const QList<int> &roles = QList<int>()) override;
119 void rowsInserted(const QModelIndex &parent, int start, int end) override;
120 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
121
122 void mouseMoveEvent(QMouseEvent *e) override;
123 void mouseReleaseEvent(QMouseEvent *e) override;
124#if QT_CONFIG(wheelevent)
125 void wheelEvent(QWheelEvent *e) override;
126#endif
127
128 void timerEvent(QTimerEvent *e) override;
129 void resizeEvent(QResizeEvent *e) override;
130#if QT_CONFIG(draganddrop)
131 void dragMoveEvent(QDragMoveEvent *e) override;
132 void dragLeaveEvent(QDragLeaveEvent *e) override;
133 void dropEvent(QDropEvent *e) override;
134 void startDrag(Qt::DropActions supportedActions) override;
135#endif // QT_CONFIG(draganddrop)
136
137 void initViewItemOption(QStyleOptionViewItem *option) const override;
138 void paintEvent(QPaintEvent *e) override;
139
140 int horizontalOffset() const override;
141 int verticalOffset() const override;
142 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
143 QRect rectForIndex(const QModelIndex &index) const;
144 void setPositionForIndex(const QPoint &position, const QModelIndex &index);
145
146 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
148 QModelIndexList selectedIndexes() const override;
149
150 void updateGeometries() override;
151
152 bool isIndexHidden(const QModelIndex &index) const override;
153
154 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
155 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
156
157 QSize viewportSizeHint() const override;
158
159private:
160 int visualIndex(const QModelIndex &index) const;
162
163 Q_DECLARE_PRIVATE(QListView)
164 Q_DISABLE_COPY(QListView)
165};
166
168
169#endif // QLISTVIEW_H
The QAbstractItemView class provides the basic functionality for item view classes.
virtual QRect visualRect(const QModelIndex &index) const =0
Returns the rectangle on the viewport occupied by the item at index.
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const =0
Returns the region from the viewport of the items in the given selection.
virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)=0
Applies the selection flags to the items in or touched by the rectangle, rect.
virtual int verticalOffset() const =0
Returns the vertical offset of the view.
void timerEvent(QTimerEvent *event) override
This function is called with the given event when a timer event is sent to the widget.
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
virtual void reset()
Reset the internal state of the view.
void mouseReleaseEvent(QMouseEvent *event) override
This function is called with the given event when a mouse button is released, after a mouse press eve...
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This slot is called when items with the given roles are changed in the model.
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
This slot is called when rows are about to be removed.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
virtual void initViewItemOption(QStyleOptionViewItem *option) const
virtual void doItemsLayout()
virtual void scrollTo(const QModelIndex &index, ScrollHint hint=EnsureVisible)=0
Scrolls the view if necessary to ensure that the item at index is visible.
virtual int horizontalOffset() const =0
Returns the horizontal offset of the view.
CursorAction
This enum describes the different ways to navigate between items,.
virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)=0
Returns a QModelIndex object pointing to the next object in the view, based on the given cursorAction...
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This slot is called when a new item becomes the current item.
void resizeEvent(QResizeEvent *event) override
This function is called with the given event when a resize event is sent to the widget.
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
virtual QModelIndexList selectedIndexes() const
This convenience function returns a list of all selected and non-hidden item indexes in the view.
virtual bool isIndexHidden(const QModelIndex &index) const =0
Returns true if the item referred to by the given index is hidden in the view, otherwise returns fals...
void mouseMoveEvent(QMouseEvent *event) override
This function is called with the given event when a mouse move event is sent to the widget.
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
virtual void updateGeometries()
QSize viewportSizeHint() const override
\inmodule QtCore
Definition qcoreevent.h:45
\inmodule QtCore
The QListView class provides a list or icon view onto a model.
Definition qlistview.h:17
ViewMode
\value ListMode The items are laid out using TopToBottom flow, with Small size and Static movement \v...
Definition qlistview.h:43
ResizeMode
\value Fixed The items will only be laid out the first time the view is shown.
Definition qlistview.h:39
Movement
\value Static The items cannot be moved by the user.
Definition qlistview.h:35
Flow
\value LeftToRight The items are laid out in the view from the left to the right.
Definition qlistview.h:37
LayoutMode
\value SinglePass The items are laid out all at once.
Definition qlistview.h:41
void indexesMoved(const QModelIndexList &indexes)
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:195
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:30
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
\inmodule QtCore
Definition qsize.h:25
\inmodule QtCore
Definition qcoreevent.h:359
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
EGLImageKHR int int EGLuint64KHR * modifiers
qreal spacing
double e
rect
[4]
uint alignment
Combined button and popup list for selecting options.
GLenum mode
GLint GLsizei GLsizei height
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLuint GLuint end
GLint GLsizei width
GLboolean enable
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLenum GLenum GLsizei void * row
GLfloat GLfloat p
[1]
GLuint GLenum option
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SIGNALS
view show()
[18] //! [19]
dialog setViewMode(QFileDialog::Detail)
[3]
edit hide()
QItemSelection * selection
[0]
spinBox setWrapping(true)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent