Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstractitemview.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 QABSTRACTITEMVIEW_H
5#define QABSTRACTITEMVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractscrollarea.h>
9#include <QtCore/qabstractitemmodel.h>
10#include <QtCore/qitemselectionmodel.h>
11#include <QtWidgets/qabstractitemdelegate.h>
12
13class tst_QAbstractItemView;
14class tst_QTreeView;
15
17
19
20class QMenu;
21class QDrag;
22class QEvent;
24
25class Q_WIDGETS_EXPORT QAbstractItemView : public QAbstractScrollArea
26{
28 Q_PROPERTY(bool autoScroll READ hasAutoScroll WRITE setAutoScroll)
29 Q_PROPERTY(int autoScrollMargin READ autoScrollMargin WRITE setAutoScrollMargin)
30 Q_PROPERTY(EditTriggers editTriggers READ editTriggers WRITE setEditTriggers)
31 Q_PROPERTY(bool tabKeyNavigation READ tabKeyNavigation WRITE setTabKeyNavigation)
32#if QT_CONFIG(draganddrop)
33 Q_PROPERTY(bool showDropIndicator READ showDropIndicator WRITE setDropIndicatorShown)
34 Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
35 Q_PROPERTY(bool dragDropOverwriteMode READ dragDropOverwriteMode WRITE setDragDropOverwriteMode)
36 Q_PROPERTY(DragDropMode dragDropMode READ dragDropMode WRITE setDragDropMode)
37 Q_PROPERTY(Qt::DropAction defaultDropAction READ defaultDropAction WRITE setDefaultDropAction)
38#endif
39 Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
40 Q_PROPERTY(SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
41 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior
42 WRITE setSelectionBehavior)
43 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
44 Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
45 Q_PROPERTY(ScrollMode verticalScrollMode READ verticalScrollMode WRITE setVerticalScrollMode
46 RESET resetVerticalScrollMode)
47 Q_PROPERTY(ScrollMode horizontalScrollMode READ horizontalScrollMode
48 WRITE setHorizontalScrollMode RESET resetHorizontalScrollMode)
49
50public:
58 Q_ENUM(SelectionMode)
59
65 Q_ENUM(SelectionBehavior)
66
73 Q_ENUM(ScrollHint)
74
76 NoEditTriggers = 0,
77 CurrentChanged = 1,
78 DoubleClicked = 2,
79 SelectedClicked = 4,
80 EditKeyPressed = 8,
81 AnyKeyPressed = 16,
82 AllEditTriggers = 31
83 };
84
85 Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
86 Q_FLAG(EditTriggers)
87
90 ScrollPerPixel
91 };
92 Q_ENUM(ScrollMode)
93
94 explicit QAbstractItemView(QWidget *parent = nullptr);
96
97 virtual void setModel(QAbstractItemModel *model);
99
100 virtual void setSelectionModel(QItemSelectionModel *selectionModel);
101 QItemSelectionModel *selectionModel() const;
102
103 void setItemDelegate(QAbstractItemDelegate *delegate);
104 QAbstractItemDelegate *itemDelegate() const;
105
106 void setSelectionMode(QAbstractItemView::SelectionMode mode);
107 QAbstractItemView::SelectionMode selectionMode() const;
108
109 void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior);
110 QAbstractItemView::SelectionBehavior selectionBehavior() const;
111
112 QModelIndex currentIndex() const;
113 QModelIndex rootIndex() const;
114
115 void setEditTriggers(EditTriggers triggers);
116 EditTriggers editTriggers() const;
117
118 void setVerticalScrollMode(ScrollMode mode);
119 ScrollMode verticalScrollMode() const;
120 void resetVerticalScrollMode();
121
122 void setHorizontalScrollMode(ScrollMode mode);
123 ScrollMode horizontalScrollMode() const;
124 void resetHorizontalScrollMode();
125
126 void setAutoScroll(bool enable);
127 bool hasAutoScroll() const;
128
129 void setAutoScrollMargin(int margin);
130 int autoScrollMargin() const;
131
132 void setTabKeyNavigation(bool enable);
133 bool tabKeyNavigation() const;
134
135#if QT_CONFIG(draganddrop)
136 void setDropIndicatorShown(bool enable);
137 bool showDropIndicator() const;
138
139 void setDragEnabled(bool enable);
140 bool dragEnabled() const;
141
142 void setDragDropOverwriteMode(bool overwrite);
143 bool dragDropOverwriteMode() const;
144
145 enum DragDropMode {
146 NoDragDrop,
147 DragOnly,
148 DropOnly,
149 DragDrop,
150 InternalMove
151 };
152 Q_ENUM(DragDropMode)
153
154 void setDragDropMode(DragDropMode behavior);
155 DragDropMode dragDropMode() const;
156
157 void setDefaultDropAction(Qt::DropAction dropAction);
158 Qt::DropAction defaultDropAction() const;
159#endif
160
161 void setAlternatingRowColors(bool enable);
162 bool alternatingRowColors() const;
163
164 void setIconSize(const QSize &size);
165 QSize iconSize() const;
166
167 void setTextElideMode(Qt::TextElideMode mode);
168 Qt::TextElideMode textElideMode() const;
169
170 virtual void keyboardSearch(const QString &search);
171
172 virtual QRect visualRect(const QModelIndex &index) const = 0;
173 virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) = 0;
174 virtual QModelIndex indexAt(const QPoint &point) const = 0;
175
176 QSize sizeHintForIndex(const QModelIndex &index) const;
177 virtual int sizeHintForRow(int row) const;
178 virtual int sizeHintForColumn(int column) const;
179
180 void openPersistentEditor(const QModelIndex &index);
181 void closePersistentEditor(const QModelIndex &index);
182 bool isPersistentEditorOpen(const QModelIndex &index) const;
183
185 QWidget *indexWidget(const QModelIndex &index) const;
186
187 void setItemDelegateForRow(int row, QAbstractItemDelegate *delegate);
188 QAbstractItemDelegate *itemDelegateForRow(int row) const;
189
190 void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate);
191 QAbstractItemDelegate *itemDelegateForColumn(int column) const;
192
193#if QT_DEPRECATED_SINCE(6, 0)
194 QT_DEPRECATED_VERSION_X_6_0("Use itemDelegateForIndex instead")
195 QAbstractItemDelegate *itemDelegate(const QModelIndex &index) const
196 { return itemDelegateForIndex(index); }
197#endif
198 virtual QAbstractItemDelegate *itemDelegateForIndex(const QModelIndex &index) const;
199
200 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
201
202 using QAbstractScrollArea::update;
203
204public Q_SLOTS:
205 virtual void reset();
206 virtual void setRootIndex(const QModelIndex &index);
207 virtual void doItemsLayout();
208 virtual void selectAll();
209 void edit(const QModelIndex &index);
210 void clearSelection();
211 void setCurrentIndex(const QModelIndex &index);
212 void scrollToTop();
213 void scrollToBottom();
214 void update(const QModelIndex &index);
215
216protected Q_SLOTS:
217 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
218 const QList<int> &roles = QList<int>());
219 virtual void rowsInserted(const QModelIndex &parent, int start, int end);
220 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
221 virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
222 virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
223 virtual void updateEditorData();
224 virtual void updateEditorGeometries();
225 virtual void updateGeometries();
226 virtual void verticalScrollbarAction(int action);
227 virtual void horizontalScrollbarAction(int action);
228 virtual void verticalScrollbarValueChanged(int value);
229 virtual void horizontalScrollbarValueChanged(int value);
230 virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
231 virtual void commitData(QWidget *editor);
232 virtual void editorDestroyed(QObject *editor);
233
238
242
244
245protected:
247
248 enum CursorAction { MoveUp, MoveDown, MoveLeft, MoveRight,
249 MoveHome, MoveEnd, MovePageUp, MovePageDown,
250 MoveNext, MovePrevious };
251 virtual QModelIndex moveCursor(CursorAction cursorAction,
252 Qt::KeyboardModifiers modifiers) = 0;
253
254 virtual int horizontalOffset() const = 0;
255 virtual int verticalOffset() const = 0;
256
257 virtual bool isIndexHidden(const QModelIndex &index) const = 0;
258
259 virtual void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) = 0;
261 virtual QModelIndexList selectedIndexes() const;
262
263 virtual bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event);
264
265 virtual QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index,
266 const QEvent *event = nullptr) const;
267
268#if QT_CONFIG(draganddrop)
269 virtual void startDrag(Qt::DropActions supportedActions);
270#endif
271
272 virtual void initViewItemOption(QStyleOptionViewItem *option) const;
273
283
284 State state() const;
285 void setState(State state);
286
287 void scheduleDelayedItemsLayout();
288 void executeDelayedItemsLayout();
289
290 void setDirtyRegion(const QRegion &region);
291 void scrollDirtyRegion(int dx, int dy);
292 QPoint dirtyRegionOffset() const;
293
294 void startAutoScroll();
295 void stopAutoScroll();
296 void doAutoScroll();
297
298 bool focusNextPrevChild(bool next) override;
299 bool event(QEvent *event) override;
300 bool viewportEvent(QEvent *event) override;
301 void mousePressEvent(QMouseEvent *event) override;
302 void mouseMoveEvent(QMouseEvent *event) override;
303 void mouseReleaseEvent(QMouseEvent *event) override;
304 void mouseDoubleClickEvent(QMouseEvent *event) override;
305#if QT_CONFIG(draganddrop)
306 void dragEnterEvent(QDragEnterEvent *event) override;
307 void dragMoveEvent(QDragMoveEvent *event) override;
308 void dragLeaveEvent(QDragLeaveEvent *event) override;
309 void dropEvent(QDropEvent *event) override;
310#endif
311 void focusInEvent(QFocusEvent *event) override;
312 void focusOutEvent(QFocusEvent *event) override;
313 void keyPressEvent(QKeyEvent *event) override;
314 void resizeEvent(QResizeEvent *event) override;
315 void timerEvent(QTimerEvent *event) override;
316 void inputMethodEvent(QInputMethodEvent *event) override;
317 bool eventFilter(QObject *object, QEvent *event) override;
318
319#if QT_CONFIG(draganddrop)
320 enum DropIndicatorPosition { OnItem, AboveItem, BelowItem, OnViewport };
321 DropIndicatorPosition dropIndicatorPosition() const;
322#endif
323
324 QSize viewportSizeHint() const override;
325
326private:
327 Q_DECLARE_PRIVATE(QAbstractItemView)
328 Q_DISABLE_COPY(QAbstractItemView)
329
330 friend class ::tst_QAbstractItemView;
331 friend class ::tst_QTreeView;
332 friend class QTreeViewPrivate; // needed to compile with MSVC
333 friend class QListModeViewBase;
334 friend class QListViewPrivate;
335 friend class QAbstractSlider;
336};
337
339
341
342#endif // QABSTRACTITEMVIEW_H
The QAbstractItemDelegate class is used to display and edit data items from a model.
EndEditHint
This enum describes the different hints that the delegate can give to the model and view components t...
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.
SelectionMode
This enum indicates how the view responds to user selections:
void activated(const QModelIndex &index)
This signal is emitted when the item specified by index is activated by the user.
virtual QRegion visualRegionForSelection(const QItemSelection &selection) const =0
Returns the region from the viewport of the items in the given selection.
void iconSizeChanged(const QSize &size)
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 doubleClicked(const QModelIndex &index)
This signal is emitted when a mouse button is double-clicked.
void entered(const QModelIndex &index)
This signal is emitted when the mouse cursor enters the item specified by index.
SelectionBehavior
\value SelectItems Selecting single items.
EditTrigger
This enum describes actions which will initiate item editing.
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...
void pressed(const QModelIndex &index)
This signal is emitted when a mouse button is pressed.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
void clicked(const QModelIndex &index)
This signal is emitted when a mouse button is left-clicked.
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...
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
void viewportEntered()
This signal is emitted when the mouse cursor enters the viewport.
The QAbstractSlider class provides an integer value within a range.
\inmodule QtGui
Definition qdrag.h:22
\inmodule QtCore
Definition qcoreevent.h:45
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
The QInputMethodEvent class provides parameters for input method events.
Definition qevent.h:625
\inmodule QtCore
The QKeyEvent class describes a key event.
Definition qevent.h:424
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:196
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:25
\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:548
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
\inmodule QtCore
Definition qvariant.h:65
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
EGLImageKHR int int EGLuint64KHR * modifiers
QOpenGLWidget * widget
[1]
opt iconSize
rect
[4]
else opt state
[0]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
InputMethodQuery
DropAction
TextElideMode
Definition qnamespace.h:188
static jboolean selectAll(JNIEnv *, jobject)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLuint GLuint end
GLboolean enable
GLuint start
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLboolean reset
GLenum query
GLenum GLenum GLsizei void * row
GLuint GLenum option
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_0(text)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_FLAG(x)
#define Q_SLOTS
#define Q_SIGNALS
view setModel(model)
[17] //! [18]
QSqlQueryModel * model
[16]
view setEditTriggers(QAbstractItemView::NoEditTriggers)
[16] //! [19] //! [20]
setIndexWidget(index, new QLineEdit)
[0]
QItemSelection * selection
[0]