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
qheaderview.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 QHEADERVIEW_H
5#define QHEADERVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractitemview.h>
9
11
13
16
17class Q_WIDGETS_EXPORT QHeaderView : public QAbstractItemView
18{
20 Q_PROPERTY(bool firstSectionMovable READ isFirstSectionMovable WRITE setFirstSectionMovable)
21 Q_PROPERTY(bool showSortIndicator READ isSortIndicatorShown WRITE setSortIndicatorShown)
22 Q_PROPERTY(bool sectionsMovable READ sectionsMovable WRITE setSectionsMovable)
23 Q_PROPERTY(bool sectionsClickable READ sectionsClickable WRITE setSectionsClickable)
24 Q_PROPERTY(bool highlightSections READ highlightSections WRITE setHighlightSections)
25 Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
26 Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes
27 WRITE setCascadingSectionResizes)
28 Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize
29 RESET resetDefaultSectionSize)
30 Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
31 Q_PROPERTY(int maximumSectionSize READ maximumSectionSize WRITE setMaximumSectionSize)
32 Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
33 Q_PROPERTY(bool sortIndicatorClearable READ isSortIndicatorClearable
34 WRITE setSortIndicatorClearable NOTIFY sortIndicatorClearableChanged)
35
36public:
37
46 Q_ENUM(ResizeMode)
47
48 explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr);
49 virtual ~QHeaderView();
50
51 void setModel(QAbstractItemModel *model) override;
52
53 Qt::Orientation orientation() const;
54 int offset() const;
55 int length() const;
56 QSize sizeHint() const override;
57 void setVisible(bool v) override;
58 int sectionSizeHint(int logicalIndex) const;
59
60 int visualIndexAt(int position) const;
61 int logicalIndexAt(int position) const;
62
63 inline int logicalIndexAt(int x, int y) const;
64 inline int logicalIndexAt(const QPoint &pos) const;
65
66 int sectionSize(int logicalIndex) const;
67 int sectionPosition(int logicalIndex) const;
68 int sectionViewportPosition(int logicalIndex) const;
69
70 void moveSection(int from, int to);
71 void swapSections(int first, int second);
72 void resizeSection(int logicalIndex, int size);
73 void resizeSections(QHeaderView::ResizeMode mode);
74
75 bool isSectionHidden(int logicalIndex) const;
76 void setSectionHidden(int logicalIndex, bool hide);
77 int hiddenSectionCount() const;
78
79 inline void hideSection(int logicalIndex);
80 inline void showSection(int logicalIndex);
81
82 int count() const;
83 int visualIndex(int logicalIndex) const;
84 int logicalIndex(int visualIndex) const;
85
86 void setSectionsMovable(bool movable);
87 bool sectionsMovable() const;
88 void setFirstSectionMovable(bool movable);
89 bool isFirstSectionMovable() const;
90
91 void setSectionsClickable(bool clickable);
92 bool sectionsClickable() const;
93
94 void setHighlightSections(bool highlight);
95 bool highlightSections() const;
96
97 ResizeMode sectionResizeMode(int logicalIndex) const;
98 void setSectionResizeMode(ResizeMode mode);
99 void setSectionResizeMode(int logicalIndex, ResizeMode mode);
100
101 void setResizeContentsPrecision(int precision);
102 int resizeContentsPrecision() const;
103
104 int stretchSectionCount() const;
105
106 void setSortIndicatorShown(bool show);
107 bool isSortIndicatorShown() const;
108
109 void setSortIndicator(int logicalIndex, Qt::SortOrder order);
110 int sortIndicatorSection() const;
111 Qt::SortOrder sortIndicatorOrder() const;
112
113 void setSortIndicatorClearable(bool clearable);
114 bool isSortIndicatorClearable() const;
115
116 bool stretchLastSection() const;
117 void setStretchLastSection(bool stretch);
118
119 bool cascadingSectionResizes() const;
120 void setCascadingSectionResizes(bool enable);
121
122 int defaultSectionSize() const;
123 void setDefaultSectionSize(int size);
124 void resetDefaultSectionSize();
125
126 int minimumSectionSize() const;
127 void setMinimumSectionSize(int size);
128 int maximumSectionSize() const;
129 void setMaximumSectionSize(int size);
130
131 Qt::Alignment defaultAlignment() const;
132 void setDefaultAlignment(Qt::Alignment alignment);
133
134 void doItemsLayout() override;
135 bool sectionsMoved() const;
136 bool sectionsHidden() const;
137
138#ifndef QT_NO_DATASTREAM
139 QByteArray saveState() const;
140 bool restoreState(const QByteArray &state);
141#endif
142
143 void reset() override;
144
145public Q_SLOTS:
146 void setOffset(int offset);
147 void setOffsetToSectionPosition(int visualIndex);
148 void setOffsetToLastSection();
149 void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
150
152 void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
153 void sectionResized(int logicalIndex, int oldSize, int newSize);
154 void sectionPressed(int logicalIndex);
155 void sectionClicked(int logicalIndex);
156 void sectionEntered(int logicalIndex);
157 void sectionDoubleClicked(int logicalIndex);
158 void sectionCountChanged(int oldCount, int newCount);
159 void sectionHandleDoubleClicked(int logicalIndex);
161 void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
162 void sortIndicatorClearableChanged(bool clearable);
163
164protected Q_SLOTS:
165 void updateSection(int logicalIndex);
166 void resizeSections();
167 void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
168 void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
169
170protected:
171 QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = nullptr);
172 void initialize();
173
174 void initializeSections();
175 void initializeSections(int start, int end);
176 void currentChanged(const QModelIndex &current, const QModelIndex &old) override;
177
178 bool event(QEvent *e) override;
179 void paintEvent(QPaintEvent *e) override;
180 void mousePressEvent(QMouseEvent *e) override;
181 void mouseMoveEvent(QMouseEvent *e) override;
182 void mouseReleaseEvent(QMouseEvent *e) override;
183 void mouseDoubleClickEvent(QMouseEvent *e) override;
184 bool viewportEvent(QEvent *e) override;
185
186 virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
187 virtual QSize sectionSizeFromContents(int logicalIndex) const;
188
189 int horizontalOffset() const override;
190 int verticalOffset() const override;
191 void updateGeometries() override;
192 void scrollContentsBy(int dx, int dy) override;
193
194 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
195 const QList<int> &roles = QList<int>()) override;
196 void rowsInserted(const QModelIndex &parent, int start, int end) override;
197
198 QRect visualRect(const QModelIndex &index) const override;
199 void scrollTo(const QModelIndex &index, ScrollHint hint) override;
200
201 QModelIndex indexAt(const QPoint &p) const override;
202 bool isIndexHidden(const QModelIndex &index) const override;
203
204 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override;
205 void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
206 QRegion visualRegionForSelection(const QItemSelection &selection) const override;
207 virtual void initStyleOptionForIndex(QStyleOptionHeader *option, int logicalIndex) const;
208 virtual void initStyleOption(QStyleOptionHeader *option) const;
209
210 friend class QTableView;
211 friend class QTreeView;
212
213private:
214 void initStyleOption(QStyleOptionFrame *option) const override;
215
216 Q_DECLARE_PRIVATE(QHeaderView)
217 Q_DISABLE_COPY(QHeaderView)
218};
219
220inline int QHeaderView::logicalIndexAt(int ax, int ay) const
221{ return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
222inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
223{ return logicalIndexAt(apos.x(), apos.y()); }
224inline void QHeaderView::hideSection(int alogicalIndex)
225{ setSectionHidden(alogicalIndex, true); }
226inline void QHeaderView::showSection(int alogicalIndex)
227{ setSectionHidden(alogicalIndex, false); }
228
230
231#endif // QHEADERVIEW_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 qbytearray.h:57
\inmodule QtCore
Definition qcoreevent.h:45
The QHeaderView class provides a header row or header column for item views.
Definition qheaderview.h:18
void geometriesChanged()
void sectionClicked(int logicalIndex)
This signal is emitted when a section is clicked.
void sectionCountChanged(int oldCount, int newCount)
This signal is emitted when the number of sections changes, i.e., when sections are added or deleted.
void sectionResized(int logicalIndex, int oldSize, int newSize)
This signal is emitted when a section is resized.
ResizeMode
The resize mode specifies the behavior of the header sections.
Definition qheaderview.h:39
void sectionPressed(int logicalIndex)
This signal is emitted when a section is pressed.
void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order)
void hideSection(int logicalIndex)
Hides the section specified by logicalIndex.
int logicalIndexAt(int position) const
Returns the section that covers the given position in the viewport.
void setSectionHidden(int logicalIndex, bool hide)
If hide is true the section specified by logicalIndex is hidden; otherwise the section is shown.
void sectionHandleDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
void sectionEntered(int logicalIndex)
void sortIndicatorClearableChanged(bool clearable)
void showSection(int logicalIndex)
Shows the section specified by logicalIndex.
Qt::Orientation orientation() const
Returns the orientation of the header.
void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
This signal is emitted when a section is moved.
void sectionDoubleClicked(int logicalIndex)
This signal is emitted when a section is double-clicked.
\inmodule QtCore
\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
\variable QStyleOptionFocusRect::backgroundColor
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
The QTableView class provides a default model/view implementation of a table view.
Definition qtableview.h:18
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
rect
[4]
uint alignment
else opt state
[0]
Combined button and popup list for selecting options.
Definition qcompare.h:63
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
SortOrder
Definition qnamespace.h:121
static jboolean setSelection(JNIEnv *, jobject, jint start, jint end)
static bool initialize()
Definition qctf.cpp:94
static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect)
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLenum GLenum GLsizei count
GLbitfield flags
GLboolean enable
GLuint start
GLenum GLuint GLintptr offset
GLint first
GLint y
struct _cl_event * event
GLboolean reset
GLfloat GLfloat p
[1]
GLuint GLenum option
GLfixed GLfixed GLint GLint order
GLenum GLint GLint * precision
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_SLOTS
#define Q_SIGNALS
view setModel(model)
[17] //! [18]
QSqlQueryModel * model
[16]
view show()
[18] //! [19]
edit hide()
QItemSelection * selection
[0]
QPainter painter(this)
[7]
scroller scrollTo(QPointF(100, 100))