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
qtreeview.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 QTREEVIEW_H
5#define QTREEVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractitemview.h>
9
10class tst_QTreeView;
11
13
15
17class QHeaderView;
18
19class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView
20{
22 Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
23 Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation)
24 Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
25 Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
26 Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
27 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
28 Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
29 Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus)
30 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
31 Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden)
32 Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick)
33
34public:
35 explicit QTreeView(QWidget *parent = nullptr);
36 ~QTreeView();
37
38 void setModel(QAbstractItemModel *model) override;
39 void setRootIndex(const QModelIndex &index) override;
40 void setSelectionModel(QItemSelectionModel *selectionModel) override;
41
42 QHeaderView *header() const;
44
45 int autoExpandDelay() const;
46 void setAutoExpandDelay(int delay);
47
48 int indentation() const;
49 void setIndentation(int i);
50 void resetIndentation();
51
52 bool rootIsDecorated() const;
53 void setRootIsDecorated(bool show);
54
55 bool uniformRowHeights() const;
56 void setUniformRowHeights(bool uniform);
57
58 bool itemsExpandable() const;
59 void setItemsExpandable(bool enable);
60
61 bool expandsOnDoubleClick() const;
62 void setExpandsOnDoubleClick(bool enable);
63
64 int columnViewportPosition(int column) const;
65 int columnWidth(int column) const;
66 void setColumnWidth(int column, int width);
67 int columnAt(int x) const;
68
69 bool isColumnHidden(int column) const;
70 void setColumnHidden(int column, bool hide);
71
72 bool isHeaderHidden() const;
73 void setHeaderHidden(bool hide);
74
75 bool isRowHidden(int row, const QModelIndex &parent) const;
76 void setRowHidden(int row, const QModelIndex &parent, bool hide);
77
78 bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
79 void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
80
81 bool isExpanded(const QModelIndex &index) const;
82 void setExpanded(const QModelIndex &index, bool expand);
83
84 void setSortingEnabled(bool enable);
85 bool isSortingEnabled() const;
86
87 void setAnimated(bool enable);
88 bool isAnimated() const;
89
90 void setAllColumnsShowFocus(bool enable);
91 bool allColumnsShowFocus() const;
92
93 void setWordWrap(bool on);
94 bool wordWrap() const;
95
96 void setTreePosition(int logicalIndex);
97 int treePosition() const;
98
99 void keyboardSearch(const QString &search) override;
100
101 QRect visualRect(const QModelIndex &index) const override;
102 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
103 QModelIndex indexAt(const QPoint &p) const override;
104 QModelIndex indexAbove(const QModelIndex &index) const;
105 QModelIndex indexBelow(const QModelIndex &index) const;
106
107 void doItemsLayout() override;
108 void reset() override;
109
110 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
111 const QList<int> &roles = QList<int>()) override;
112 void selectAll() override;
113
115 void expanded(const QModelIndex &index);
116 void collapsed(const QModelIndex &index);
117
118public Q_SLOTS:
119 void hideColumn(int column);
120 void showColumn(int column);
121 void expand(const QModelIndex &index);
122 void collapse(const QModelIndex &index);
123 void resizeColumnToContents(int column);
124 void sortByColumn(int column, Qt::SortOrder order);
125 void expandAll();
126 void expandRecursively(const QModelIndex &index, int depth = -1);
127 void collapseAll();
128 void expandToDepth(int depth);
129
130protected Q_SLOTS:
131 void columnResized(int column, int oldSize, int newSize);
132 void columnCountChanged(int oldCount, int newCount);
133 void columnMoved();
134 void reexpand();
135 void rowsRemoved(const QModelIndex &parent, int first, int last);
136 void verticalScrollbarValueChanged(int value) override;
137
138protected:
139 QTreeView(QTreeViewPrivate &dd, QWidget *parent = nullptr);
140 void scrollContentsBy(int dx, int dy) override;
141 void rowsInserted(const QModelIndex &parent, int start, int end) override;
142 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
143
144 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
145 int horizontalOffset() const override;
146 int verticalOffset() const override;
147
148 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
149 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
150 QModelIndexList selectedIndexes() const override;
151
152 void changeEvent(QEvent *event) override;
153 void timerEvent(QTimerEvent *event) override;
154 void paintEvent(QPaintEvent *event) override;
155
156 void drawTree(QPainter *painter, const QRegion &region) const;
157 virtual void drawRow(QPainter *painter,
158 const QStyleOptionViewItem &options,
159 const QModelIndex &index) const;
160 virtual void drawBranches(QPainter *painter,
161 const QRect &rect,
162 const QModelIndex &index) const;
163
164 void mousePressEvent(QMouseEvent *event) override;
165 void mouseReleaseEvent(QMouseEvent *event) override;
166 void mouseDoubleClickEvent(QMouseEvent *event) override;
167 void mouseMoveEvent(QMouseEvent *event) override;
168 void keyPressEvent(QKeyEvent *event) override;
169#if QT_CONFIG(draganddrop)
170 void dragMoveEvent(QDragMoveEvent *event) override;
171#endif
172 bool viewportEvent(QEvent *event) override;
173
174 void updateGeometries() override;
175
176 QSize viewportSizeHint() const override;
177
178 int sizeHintForColumn(int column) const override;
179 int indexRowSizeHint(const QModelIndex &index) const;
180 int rowHeight(const QModelIndex &index) const;
181
182 void horizontalScrollbarAction(int action) override;
183
184 bool isIndexHidden(const QModelIndex &index) const override;
185 void selectionChanged(const QItemSelection &selected,
186 const QItemSelection &deselected) override;
187 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
188
189private:
190 friend class ::tst_QTreeView;
191 friend class QAccessibleTable;
192 friend class QAccessibleTree;
193 friend class QAccessibleTableCell;
194 int visualIndex(const QModelIndex &index) const;
195
196 Q_DECLARE_PRIVATE(QTreeView)
197 Q_DISABLE_COPY(QTreeView)
198};
199
201
202#endif // QTREEVIEW_H
The QAbstractItemView class provides the basic functionality for item view classes.
CursorAction
This enum describes the different ways to navigate between items,.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
\inmodule QtCore
Definition qcoreevent.h:45
The QHeaderView class provides a header row or header column for item views.
Definition qheaderview.h:18
\inmodule QtCore
The QKeyEvent class describes a key event.
Definition qevent.h:424
Definition qlist.h:75
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:196
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\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
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qcoreevent.h:366
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
EGLImageKHR int int EGLuint64KHR * modifiers
rect
[4]
Combined button and popup list for selecting options.
Definition qcompare.h:63
static jboolean setSelection(JNIEnv *, jobject, jint start, jint end)
static jboolean selectAll(JNIEnv *, jobject)
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect)
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLuint index
[2]
GLuint GLuint end
GLint GLsizei width
GLboolean enable
GLuint start
GLint first
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLboolean reset
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void GLsizei void void * span
GLfloat GLfloat p
[1]
GLfixed GLfixed GLint GLint order
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
#define explicit
view setModel(model)
[17] //! [18]
QSqlQueryModel * model
[16]
view show()
[18] //! [19]
edit hide()
QItemSelection * selection
[0]
QPainter painter(this)
[7]
textPart setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"text\""))
scroller scrollTo(QPointF(100, 100))