Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QTREEVIEW_H
6#define QTREEVIEW_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtWidgets/qabstractitemview.h>
10
11class tst_QTreeView;
12
14
15QT_BEGIN_NAMESPACE
16
17class QTreeViewPrivate;
18class QHeaderView;
19
20class Q_WIDGETS_EXPORT QTreeView : public QAbstractItemView
21{
22 Q_OBJECT
23 Q_PROPERTY(int autoExpandDelay READ autoExpandDelay WRITE setAutoExpandDelay)
24 Q_PROPERTY(int indentation READ indentation WRITE setIndentation RESET resetIndentation)
25 Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
26 Q_PROPERTY(bool uniformRowHeights READ uniformRowHeights WRITE setUniformRowHeights)
27 Q_PROPERTY(bool itemsExpandable READ itemsExpandable WRITE setItemsExpandable)
28 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
29 Q_PROPERTY(bool animated READ isAnimated WRITE setAnimated)
30 Q_PROPERTY(bool allColumnsShowFocus READ allColumnsShowFocus WRITE setAllColumnsShowFocus)
31 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
32 Q_PROPERTY(bool headerHidden READ isHeaderHidden WRITE setHeaderHidden)
33 Q_PROPERTY(bool expandsOnDoubleClick READ expandsOnDoubleClick WRITE setExpandsOnDoubleClick)
34
35public:
36 explicit QTreeView(QWidget *parent = nullptr);
37 ~QTreeView();
38
39 void setModel(QAbstractItemModel *model) override;
40 void setRootIndex(const QModelIndex &index) override;
41 void setSelectionModel(QItemSelectionModel *selectionModel) override;
42
43 QHeaderView *header() const;
44 void setHeader(QHeaderView *header);
45
46 int autoExpandDelay() const;
47 void setAutoExpandDelay(int delay);
48
49 int indentation() const;
50 void setIndentation(int i);
51 void resetIndentation();
52
53 bool rootIsDecorated() const;
54 void setRootIsDecorated(bool show);
55
56 bool uniformRowHeights() const;
57 void setUniformRowHeights(bool uniform);
58
59 bool itemsExpandable() const;
60 void setItemsExpandable(bool enable);
61
62 bool expandsOnDoubleClick() const;
63 void setExpandsOnDoubleClick(bool enable);
64
65 int columnViewportPosition(int column) const;
66 int columnWidth(int column) const;
67 void setColumnWidth(int column, int width);
68 int columnAt(int x) const;
69
70 bool isColumnHidden(int column) const;
71 void setColumnHidden(int column, bool hide);
72
73 bool isHeaderHidden() const;
74 void setHeaderHidden(bool hide);
75
76 bool isRowHidden(int row, const QModelIndex &parent) const;
77 void setRowHidden(int row, const QModelIndex &parent, bool hide);
78
79 bool isFirstColumnSpanned(int row, const QModelIndex &parent) const;
80 void setFirstColumnSpanned(int row, const QModelIndex &parent, bool span);
81
82 bool isExpanded(const QModelIndex &index) const;
83 void setExpanded(const QModelIndex &index, bool expand);
84
85 void setSortingEnabled(bool enable);
86 bool isSortingEnabled() const;
87
88 void setAnimated(bool enable);
89 bool isAnimated() const;
90
91 void setAllColumnsShowFocus(bool enable);
92 bool allColumnsShowFocus() const;
93
94 void setWordWrap(bool on);
95 bool wordWrap() const;
96
97 void setTreePosition(int logicalIndex);
98 int treePosition() const;
99
100 void keyboardSearch(const QString &search) override;
101
102 QRect visualRect(const QModelIndex &index) const override;
103 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
104 QModelIndex indexAt(const QPoint &p) const override;
105 QModelIndex indexAbove(const QModelIndex &index) const;
106 QModelIndex indexBelow(const QModelIndex &index) const;
107
108 void doItemsLayout() override;
109 void reset() override;
110
111 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
112 const QList<int> &roles = QList<int>()) override;
113 void selectAll() override;
114
115Q_SIGNALS:
116 void expanded(const QModelIndex &index);
117 void collapsed(const QModelIndex &index);
118
119public Q_SLOTS:
120 void hideColumn(int column);
121 void showColumn(int column);
122 void expand(const QModelIndex &index);
123 void collapse(const QModelIndex &index);
124 void resizeColumnToContents(int column);
125 void sortByColumn(int column, Qt::SortOrder order);
126 void expandAll();
127 void expandRecursively(const QModelIndex &index, int depth = -1);
128 void collapseAll();
129 void expandToDepth(int depth);
130
131protected Q_SLOTS:
132 void columnResized(int column, int oldSize, int newSize);
133 void columnCountChanged(int oldCount, int newCount);
134 void columnMoved();
135 void reexpand();
136 void rowsRemoved(const QModelIndex &parent, int first, int last);
137 void verticalScrollbarValueChanged(int value) override;
138
139protected:
140 QTreeView(QTreeViewPrivate &dd, QWidget *parent = nullptr);
141 void scrollContentsBy(int dx, int dy) override;
142 void rowsInserted(const QModelIndex &parent, int start, int end) override;
143 void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
144
145 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
146 int horizontalOffset() const override;
147 int verticalOffset() const override;
148
149 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
150 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
151 QModelIndexList selectedIndexes() const override;
152
153 void changeEvent(QEvent *event) override;
154 void timerEvent(QTimerEvent *event) override;
155 void paintEvent(QPaintEvent *event) override;
156
157 void drawTree(QPainter *painter, const QRegion &region) const;
158 virtual void drawRow(QPainter *painter,
159 const QStyleOptionViewItem &options,
160 const QModelIndex &index) const;
161 virtual void drawBranches(QPainter *painter,
162 const QRect &rect,
163 const QModelIndex &index) const;
164
165 void mousePressEvent(QMouseEvent *event) override;
166 void mouseReleaseEvent(QMouseEvent *event) override;
167 void mouseDoubleClickEvent(QMouseEvent *event) override;
168 void mouseMoveEvent(QMouseEvent *event) override;
169 void keyPressEvent(QKeyEvent *event) override;
170#if QT_CONFIG(draganddrop)
171 void dragMoveEvent(QDragMoveEvent *event) override;
172#endif
173 bool viewportEvent(QEvent *event) override;
174
175 void updateGeometries() override;
176
177 QSize viewportSizeHint() const override;
178
179 int sizeHintForColumn(int column) const override;
180 int indexRowSizeHint(const QModelIndex &index) const;
181 int rowHeight(const QModelIndex &index) const;
182
183 void horizontalScrollbarAction(int action) override;
184
185 bool isIndexHidden(const QModelIndex &index) const override;
186 void selectionChanged(const QItemSelection &selected,
187 const QItemSelection &deselected) override;
188 void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
189
190private:
191 friend class ::tst_QTreeView;
192 friend class QAccessibleTable;
193 friend class QAccessibleTree;
194 friend class QAccessibleTableCell;
195 int visualIndex(const QModelIndex &index) const;
196
197 Q_DECLARE_PRIVATE(QTreeView)
198 Q_DISABLE_COPY(QTreeView)
199};
200
201QT_END_NAMESPACE
202
203#endif // QTREEVIEW_H
QFileDialogComboBox(QWidget *parent=nullptr)
QStringList history() const
void setHistory(const QStringList &paths)
void setFileDialogPrivate(QFileDialogPrivate *d_pointer)
void showPopup() override
Displays the list of items in the combobox.
void paintEvent(QPaintEvent *) override
\reimp
void keyPressEvent(QKeyEvent *e) override
FIXME: this is a hack to avoid propagating key press events to the dialog and from there to the "Ok" ...
void setFileDialogPrivate(QFileDialogPrivate *d_pointer)
QFileDialogLineEdit(QWidget *parent=nullptr)
void setFileDialogPrivate(QFileDialogPrivate *d_pointer)
QSize sizeHint() const override
QFileDialogListView(QWidget *parent=nullptr)
void keyPressEvent(QKeyEvent *e) override
void keyPressEvent(QKeyEvent *e) override
QSize sizeHint() const override
QFileDialogTreeView(QWidget *parent)
void setFileDialogPrivate(QFileDialogPrivate *d_pointer)
The QFileDialog class provides a dialog that allows users to select files or directories.
Definition qfiledialog.h:29
The QListView class provides a list or icon view onto a model.
Definition qlistview.h:18
Definition qlist.h:80
\inmodule QtCore
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:21
QT_REQUIRE_CONFIG(animation)
static QUrl _qt_get_directory(const QUrl &url, const QFileInfo &local)
static void _qt_init_lastVisited()
QStringList qt_strip_filters(const QStringList &filters)
QStringList qt_make_filter_list(const QString &filter)
static QString fileFromPath(const QString &rootPath, QString path)
static bool isCaseSensitiveFileSystem(const QString &path)
QT_REQUIRE_CONFIG(filedialog)
QT_REQUIRE_CONFIG(treeview)
QFileDialogArgs(const QUrl &url={})