Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtableview.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 QTABLEVIEW_H
5#define QTABLEVIEW_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qabstractitemview.h>
9
11
13
14class QHeaderView;
16
17class Q_WIDGETS_EXPORT QTableView : public QAbstractItemView
18{
20 Q_PROPERTY(bool showGrid READ showGrid WRITE setShowGrid)
21 Q_PROPERTY(Qt::PenStyle gridStyle READ gridStyle WRITE setGridStyle)
22 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
23 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
24#if QT_CONFIG(abstractbutton)
25 Q_PROPERTY(bool cornerButtonEnabled READ isCornerButtonEnabled WRITE setCornerButtonEnabled)
26#endif
27
28public:
29 explicit QTableView(QWidget *parent = nullptr);
31
32 void setModel(QAbstractItemModel *model) override;
33 void setRootIndex(const QModelIndex &index) override;
34 void setSelectionModel(QItemSelectionModel *selectionModel) override;
35 void doItemsLayout() override;
36
37 QHeaderView *horizontalHeader() const;
38 QHeaderView *verticalHeader() const;
39 void setHorizontalHeader(QHeaderView *header);
40 void setVerticalHeader(QHeaderView *header);
41
42 int rowViewportPosition(int row) const;
43 int rowAt(int y) const;
44
45 void setRowHeight(int row, int height);
46 int rowHeight(int row) const;
47
48 int columnViewportPosition(int column) const;
49 int columnAt(int x) const;
50
51 void setColumnWidth(int column, int width);
52 int columnWidth(int column) const;
53
54 bool isRowHidden(int row) const;
55 void setRowHidden(int row, bool hide);
56
57 bool isColumnHidden(int column) const;
58 void setColumnHidden(int column, bool hide);
59
60 void setSortingEnabled(bool enable);
61 bool isSortingEnabled() const;
62
63 bool showGrid() const;
64
65 Qt::PenStyle gridStyle() const;
66 void setGridStyle(Qt::PenStyle style);
67
68 void setWordWrap(bool on);
69 bool wordWrap() const;
70
71#if QT_CONFIG(abstractbutton)
72 void setCornerButtonEnabled(bool enable);
73 bool isCornerButtonEnabled() const;
74#endif
75
76 QRect visualRect(const QModelIndex &index) const override;
77 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
78 QModelIndex indexAt(const QPoint &p) const override;
79
80 void setSpan(int row, int column, int rowSpan, int columnSpan);
81 int rowSpan(int row, int column) const;
82 int columnSpan(int row, int column) const;
83 void clearSpans();
84
85
86public Q_SLOTS:
87 void selectRow(int row);
88 void selectColumn(int column);
89 void hideRow(int row);
90 void hideColumn(int column);
91 void showRow(int row);
92 void showColumn(int column);
93 void resizeRowToContents(int row);
94 void resizeRowsToContents();
95 void resizeColumnToContents(int column);
96 void resizeColumnsToContents();
97 void sortByColumn(int column, Qt::SortOrder order);
98 void setShowGrid(bool show);
99
100protected Q_SLOTS:
101 void rowMoved(int row, int oldIndex, int newIndex);
102 void columnMoved(int column, int oldIndex, int newIndex);
103 void rowResized(int row, int oldHeight, int newHeight);
104 void columnResized(int column, int oldWidth, int newWidth);
105 void rowCountChanged(int oldCount, int newCount);
106 void columnCountChanged(int oldCount, int newCount);
107
108protected:
110 void scrollContentsBy(int dx, int dy) override;
111
112 void initViewItemOption(QStyleOptionViewItem *option) const override;
113 void paintEvent(QPaintEvent *e) override;
114
115 void timerEvent(QTimerEvent *event) override;
116
117 int horizontalOffset() const override;
118 int verticalOffset() const override;
119 QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
120
121 void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override;
123 QModelIndexList selectedIndexes() const override;
124
125 void updateGeometries() override;
126
127 QSize viewportSizeHint() const override;
128
129 int sizeHintForRow(int row) const override;
130 int sizeHintForColumn(int column) const override;
131
132 void verticalScrollbarAction(int action) override;
133 void horizontalScrollbarAction(int action) override;
134
135 bool isIndexHidden(const QModelIndex &index) const override;
136
137 void selectionChanged(const QItemSelection &selected,
138 const QItemSelection &deselected) override;
139 void currentChanged(const QModelIndex &current,
140 const QModelIndex &previous) override;
141
142private:
143 friend class QAccessibleItemView;
144 int visualIndex(const QModelIndex &index) const;
145
146 Q_DECLARE_PRIVATE(QTableView)
147 Q_DISABLE_COPY(QTableView)
148 Q_PRIVATE_SLOT(d_func(), void _q_selectRow(int))
149 Q_PRIVATE_SLOT(d_func(), void _q_selectColumn(int))
150 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedRows(QModelIndex,int,int))
151 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanInsertedColumns(QModelIndex,int,int))
152 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedRows(QModelIndex,int,int))
153 Q_PRIVATE_SLOT(d_func(), void _q_updateSpanRemovedColumns(QModelIndex,int,int))
154 Q_PRIVATE_SLOT(d_func(), void _q_sortIndicatorChanged(int column, Qt::SortOrder order))
155};
156
158
159#endif // QTABLEVIEW_H
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 setSelectionModel(QItemSelectionModel *selectionModel)
Sets the current selection model to the given selectionModel.
void timerEvent(QTimerEvent *event) override
This function is called with the given event when a timer event is sent to the widget.
virtual void verticalScrollbarAction(int action)
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This slot is called when the selection is changed.
virtual void setModel(QAbstractItemModel *model)
Sets the model for the view to present.
virtual void setRootIndex(const QModelIndex &index)
Sets the root item to the item at the given index.
virtual void initViewItemOption(QStyleOptionViewItem *option) const
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.
virtual QModelIndexList selectedIndexes() const
This convenience function returns a list of all selected and non-hidden item indexes in the view.
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 int sizeHintForColumn(int column) const
Returns the width size hint for the specified column or -1 if there is no model.
virtual QModelIndex indexAt(const QPoint &point) const =0
Returns the model index of the item at the viewport coordinates point.
virtual void updateGeometries()
QSize viewportSizeHint() const override
virtual void horizontalScrollbarAction(int action)
virtual int sizeHintForRow(int row) const
Returns the height size hint for the specified row or -1 if there is no model.
The QHeaderView class provides a header row or header column for item views.
Definition qheaderview.h:18
\inmodule QtCore
\inmodule QtCore
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtCore\reentrant
Definition qpoint.h:23
\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
The QTableView class provides a default model/view implementation of a table view.
Definition qtableview.h:18
\inmodule QtCore
Definition qcoreevent.h:359
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
EGLImageKHR int int EGLuint64KHR * modifiers
double e
rect
[4]
Combined button and popup list for selecting options.
SortOrder
Definition qnamespace.h:120
static QString header(const QString &name)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLuint index
[2]
GLint GLsizei width
GLboolean enable
GLint y
GLenum GLenum GLsizei void GLsizei void * column
struct _cl_event * event
GLenum GLenum GLsizei void * row
GLfloat GLfloat p
[1]
GLuint GLenum option
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_PRIVATE_SLOT(d, signature)
QSqlQueryModel * model
[16]
view show()
[18] //! [19]
edit hide()
QItemSelection * selection
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent