Qt 6.x
The Qt SDK
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 highlightSections READ highlightSections WRITE setHighlightSections)
23 Q_PROPERTY(bool stretchLastSection READ stretchLastSection WRITE setStretchLastSection)
24 Q_PROPERTY(bool cascadingSectionResizes READ cascadingSectionResizes
25 WRITE setCascadingSectionResizes)
26 Q_PROPERTY(int defaultSectionSize READ defaultSectionSize WRITE setDefaultSectionSize
27 RESET resetDefaultSectionSize)
28 Q_PROPERTY(int minimumSectionSize READ minimumSectionSize WRITE setMinimumSectionSize)
29 Q_PROPERTY(int maximumSectionSize READ maximumSectionSize WRITE setMaximumSectionSize)
30 Q_PROPERTY(Qt::Alignment defaultAlignment READ defaultAlignment WRITE setDefaultAlignment)
31 Q_PROPERTY(bool sortIndicatorClearable READ isSortIndicatorClearable
32 WRITE setSortIndicatorClearable NOTIFY sortIndicatorClearableChanged)
33
34public:
35
37 {
42 Custom = Fixed
43 };
44 Q_ENUM(ResizeMode)
45
46 explicit QHeaderView(Qt::Orientation orientation, QWidget *parent = nullptr);
47 virtual ~QHeaderView();
48
49 void setModel(QAbstractItemModel *model) override;
50
51 Qt::Orientation orientation() const;
52 int offset() const;
53 int length() const;
54 QSize sizeHint() const override;
55 void setVisible(bool v) override;
56 int sectionSizeHint(int logicalIndex) const;
57
58 int visualIndexAt(int position) const;
59 int logicalIndexAt(int position) const;
60
61 inline int logicalIndexAt(int x, int y) const;
62 inline int logicalIndexAt(const QPoint &pos) const;
63
64 int sectionSize(int logicalIndex) const;
65 int sectionPosition(int logicalIndex) const;
66 int sectionViewportPosition(int logicalIndex) const;
67
68 void moveSection(int from, int to);
69 void swapSections(int first, int second);
70 void resizeSection(int logicalIndex, int size);
71 void resizeSections(QHeaderView::ResizeMode mode);
72
73 bool isSectionHidden(int logicalIndex) const;
74 void setSectionHidden(int logicalIndex, bool hide);
75 int hiddenSectionCount() const;
76
77 inline void hideSection(int logicalIndex);
78 inline void showSection(int logicalIndex);
79
80 int count() const;
81 int visualIndex(int logicalIndex) const;
82 int logicalIndex(int visualIndex) const;
83
84 void setSectionsMovable(bool movable);
85 bool sectionsMovable() const;
86 void setFirstSectionMovable(bool movable);
87 bool isFirstSectionMovable() const;
88
89 void setSectionsClickable(bool clickable);
90 bool sectionsClickable() const;
91
92 void setHighlightSections(bool highlight);
93 bool highlightSections() const;
94
95 ResizeMode sectionResizeMode(int logicalIndex) const;
96 void setSectionResizeMode(ResizeMode mode);
97 void setSectionResizeMode(int logicalIndex, ResizeMode mode);
98
99 void setResizeContentsPrecision(int precision);
100 int resizeContentsPrecision() const;
101
102 int stretchSectionCount() const;
103
104 void setSortIndicatorShown(bool show);
105 bool isSortIndicatorShown() const;
106
107 void setSortIndicator(int logicalIndex, Qt::SortOrder order);
108 int sortIndicatorSection() const;
109 Qt::SortOrder sortIndicatorOrder() const;
110
111 void setSortIndicatorClearable(bool clearable);
112 bool isSortIndicatorClearable() const;
113
114 bool stretchLastSection() const;
115 void setStretchLastSection(bool stretch);
116
117 bool cascadingSectionResizes() const;
118 void setCascadingSectionResizes(bool enable);
119
120 int defaultSectionSize() const;
121 void setDefaultSectionSize(int size);
122 void resetDefaultSectionSize();
123
124 int minimumSectionSize() const;
125 void setMinimumSectionSize(int size);
126 int maximumSectionSize() const;
127 void setMaximumSectionSize(int size);
128
129 Qt::Alignment defaultAlignment() const;
130 void setDefaultAlignment(Qt::Alignment alignment);
131
132 void doItemsLayout() override;
133 bool sectionsMoved() const;
134 bool sectionsHidden() const;
135
136#ifndef QT_NO_DATASTREAM
137 QByteArray saveState() const;
138 bool restoreState(const QByteArray &state);
139#endif
140
141 void reset() override;
142
143public Q_SLOTS:
144 void setOffset(int offset);
145 void setOffsetToSectionPosition(int visualIndex);
146 void setOffsetToLastSection();
147 void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast);
148
150 void sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex);
151 void sectionResized(int logicalIndex, int oldSize, int newSize);
152 void sectionPressed(int logicalIndex);
153 void sectionClicked(int logicalIndex);
154 void sectionEntered(int logicalIndex);
155 void sectionDoubleClicked(int logicalIndex);
156 void sectionCountChanged(int oldCount, int newCount);
157 void sectionHandleDoubleClicked(int logicalIndex);
159 void sortIndicatorChanged(int logicalIndex, Qt::SortOrder order);
160 void sortIndicatorClearableChanged(bool clearable);
161
162protected Q_SLOTS:
163 void updateSection(int logicalIndex);
164 void resizeSections();
165 void sectionsInserted(const QModelIndex &parent, int logicalFirst, int logicalLast);
166 void sectionsAboutToBeRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast);
167
168protected:
169 QHeaderView(QHeaderViewPrivate &dd, Qt::Orientation orientation, QWidget *parent = nullptr);
170 void initialize();
171
172 void initializeSections();
173 void initializeSections(int start, int end);
174 void currentChanged(const QModelIndex &current, const QModelIndex &old) override;
175
176 bool event(QEvent *e) override;
177 void paintEvent(QPaintEvent *e) override;
178 void mousePressEvent(QMouseEvent *e) override;
179 void mouseMoveEvent(QMouseEvent *e) override;
180 void mouseReleaseEvent(QMouseEvent *e) override;
181 void mouseDoubleClickEvent(QMouseEvent *e) override;
182 bool viewportEvent(QEvent *e) override;
183
184 virtual void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
185 virtual QSize sectionSizeFromContents(int logicalIndex) const;
186
187 int horizontalOffset() const override;
188 int verticalOffset() const override;
189 void updateGeometries() override;
190 void scrollContentsBy(int dx, int dy) override;
191
192 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
193 const QList<int> &roles = QList<int>()) override;
194 void rowsInserted(const QModelIndex &parent, int start, int end) override;
195
196 QRect visualRect(const QModelIndex &index) const override;
197 void scrollTo(const QModelIndex &index, ScrollHint hint) override;
198
199 QModelIndex indexAt(const QPoint &p) const override;
200 bool isIndexHidden(const QModelIndex &index) const override;
201
202 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers) override;
203 void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
205 virtual void initStyleOptionForIndex(QStyleOptionHeader *option, int logicalIndex) const;
206 virtual void initStyleOption(QStyleOptionHeader *option) const;
207
208 friend class QTableView;
209 friend class QTreeView;
210
211private:
212 void initStyleOption(QStyleOptionFrame *option) const override;
213
214 // ### Qt6: make them protected slots in QHeaderViewPrivate
215 Q_PRIVATE_SLOT(d_func(), void _q_sectionsRemoved(const QModelIndex &parent, int logicalFirst, int logicalLast))
216 Q_PRIVATE_SLOT(d_func(), void _q_sectionsAboutToBeMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination))
217 Q_PRIVATE_SLOT(d_func(), void _q_sectionsMoved(const QModelIndex &sourceParent, int logicalStart, int logicalEnd, const QModelIndex &destinationParent, int logicalDestination))
218 Q_PRIVATE_SLOT(d_func(), void _q_sectionsAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(),
220 Q_PRIVATE_SLOT(d_func(), void _q_sectionsChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(),
222 Q_DECLARE_PRIVATE(QHeaderView)
223 Q_DISABLE_COPY(QHeaderView)
224};
225
226inline int QHeaderView::logicalIndexAt(int ax, int ay) const
227{ return orientation() == Qt::Horizontal ? logicalIndexAt(ax) : logicalIndexAt(ay); }
228inline int QHeaderView::logicalIndexAt(const QPoint &apos) const
229{ return logicalIndexAt(apos.x(), apos.y()); }
230inline void QHeaderView::hideSection(int alogicalIndex)
231{ setSectionHidden(alogicalIndex, true); }
232inline void QHeaderView::showSection(int alogicalIndex)
233{ setSectionHidden(alogicalIndex, false); }
234
236
237#endif // QHEADERVIEW_H
LayoutChangeHint
This enum describes the way the model changes layout.
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.
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.
bool viewportEvent(QEvent *event) override
This function is used to handle tool tips, and What's This? mode, if the given event is a QEvent::Too...
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
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.
ScrollHint
\value EnsureVisible Scroll to ensure that the item is visible.
void mousePressEvent(QMouseEvent *event) override
This function is called with the given event when a mouse button is pressed while the cursor is insid...
virtual void rowsInserted(const QModelIndex &parent, int start, int end)
This slot is called when rows are inserted.
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.
void mouseDoubleClickEvent(QMouseEvent *event) override
This function is called with the given event when a mouse button is double clicked inside the widget.
virtual void updateGeometries()
\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:37
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
Definition qlist.h:74
\inmodule QtCore
\inmodule QtGui
Definition qevent.h:195
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\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
double e
rect
[4]
uint alignment
else opt state
[0]
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:97
@ Horizontal
Definition qnamespace.h:98
SortOrder
Definition qnamespace.h:120
static bool initialize()
Definition qctf.cpp:67
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
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_PRIVATE_SLOT(d, signature)
#define Q_SIGNALS
QSqlQueryModel * model
[16]
view show()
[18] //! [19]
edit hide()
QItemSelection * selection
[0]
QPainter painter(this)
[7]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent