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
qtabbar.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 QTABBAR_H
6#define QTABBAR_H
7
8#include <QtWidgets/qtwidgetsglobal.h>
9#include <QtWidgets/qwidget.h>
10
12
13QT_BEGIN_NAMESPACE
14
15class QIcon;
16class QTabBarPrivate;
17class QStyleOptionTab;
18
19class Q_WIDGETS_EXPORT QTabBar: public QWidget
20{
21 Q_OBJECT
22
23 Q_PROPERTY(Shape shape READ shape WRITE setShape)
24 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
25 Q_PROPERTY(int count READ count)
26 Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
27 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
28 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
29 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
30 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
31 Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove
32 WRITE setSelectionBehaviorOnRemove)
33 Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
34 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
35 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
36 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
37 Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
38
39public:
40 explicit QTabBar(QWidget *parent = nullptr);
41 ~QTabBar();
42
43 enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
44 TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
45 };
46 Q_ENUM(Shape)
47
48 enum ButtonPosition {
49 LeftSide,
50 RightSide
51 };
52
53 enum SelectionBehavior {
54 SelectLeftTab,
55 SelectRightTab,
56 SelectPreviousTab
57 };
58
59 Shape shape() const;
60 void setShape(Shape shape);
61
62 int addTab(const QString &text);
63 int addTab(const QIcon &icon, const QString &text);
64
65 int insertTab(int index, const QString &text);
66 int insertTab(int index, const QIcon&icon, const QString &text);
67
68 void removeTab(int index);
69 void moveTab(int from, int to);
70
71 bool isTabEnabled(int index) const;
72 void setTabEnabled(int index, bool enabled);
73
74 bool isTabVisible(int index) const;
75 void setTabVisible(int index, bool visible);
76
77 QString tabText(int index) const;
78 void setTabText(int index, const QString &text);
79
80 QColor tabTextColor(int index) const;
81 void setTabTextColor(int index, const QColor &color);
82
83 QIcon tabIcon(int index) const;
84 void setTabIcon(int index, const QIcon &icon);
85
86 Qt::TextElideMode elideMode() const;
87 void setElideMode(Qt::TextElideMode mode);
88
89#if QT_CONFIG(tooltip)
90 void setTabToolTip(int index, const QString &tip);
91 QString tabToolTip(int index) const;
92#endif
93
94#if QT_CONFIG(whatsthis)
95 void setTabWhatsThis(int index, const QString &text);
96 QString tabWhatsThis(int index) const;
97#endif
98
99 void setTabData(int index, const QVariant &data);
100 QVariant tabData(int index) const;
101
102 QRect tabRect(int index) const;
103 int tabAt(const QPoint &pos) const;
104
105 int currentIndex() const;
106 int count() const;
107
108 QSize sizeHint() const override;
109 QSize minimumSizeHint() const override;
110
111 void setDrawBase(bool drawTheBase);
112 bool drawBase() const;
113
114 QSize iconSize() const;
115 void setIconSize(const QSize &size);
116
117 bool usesScrollButtons() const;
118 void setUsesScrollButtons(bool useButtons);
119
120 bool tabsClosable() const;
121 void setTabsClosable(bool closable);
122
123 void setTabButton(int index, ButtonPosition position, QWidget *widget);
124 QWidget *tabButton(int index, ButtonPosition position) const;
125
126 SelectionBehavior selectionBehaviorOnRemove() const;
127 void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
128
129 bool expanding() const;
130 void setExpanding(bool enabled);
131
132 bool isMovable() const;
133 void setMovable(bool movable);
134
135 bool documentMode() const;
136 void setDocumentMode(bool set);
137
138 bool autoHide() const;
139 void setAutoHide(bool hide);
140
141 bool changeCurrentOnDrag() const;
142 void setChangeCurrentOnDrag(bool change);
143
144#if QT_CONFIG(accessibility)
145 QString accessibleTabName(int index) const;
146 void setAccessibleTabName(int index, const QString &name);
147#endif
148
149public Q_SLOTS:
150 void setCurrentIndex(int index);
151
152Q_SIGNALS:
153 void currentChanged(int index);
154 void tabCloseRequested(int index);
155 void tabMoved(int from, int to);
156 void tabBarClicked(int index);
157 void tabBarDoubleClicked(int index);
158
159protected:
160 virtual QSize tabSizeHint(int index) const;
161 virtual QSize minimumTabSizeHint(int index) const;
162 virtual void tabInserted(int index);
163 virtual void tabRemoved(int index);
164 virtual void tabLayoutChange();
165
166 bool event(QEvent *) override;
167 void resizeEvent(QResizeEvent *) override;
168 void showEvent(QShowEvent *) override;
169 void hideEvent(QHideEvent *) override;
170 void paintEvent(QPaintEvent *) override;
171 void mousePressEvent(QMouseEvent *) override;
172 void mouseMoveEvent(QMouseEvent *) override;
173 void mouseReleaseEvent(QMouseEvent *) override;
174 void mouseDoubleClickEvent(QMouseEvent *) override;
175#if QT_CONFIG(wheelevent)
176 void wheelEvent(QWheelEvent *event) override;
177#endif
178 void keyPressEvent(QKeyEvent *) override;
179 void changeEvent(QEvent *) override;
180 void timerEvent(QTimerEvent *event) override;
181 virtual void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
182
183#if QT_CONFIG(accessibility)
184 friend class QAccessibleTabBar;
185#endif
186private:
187 Q_DISABLE_COPY(QTabBar)
188 Q_DECLARE_PRIVATE(QTabBar)
189};
190
191QT_END_NAMESPACE
192
193#endif // QTABBAR_H
The QTabBar class provides a tab bar, e.g.
Definition qtabbar.h:20
QStackedWidget * stack
QWidget * rightCornerWidget
void tabMoved(int from, int to)
bool isAutoHidden() const
void updateTabBarPosition()
QWidget * leftCornerWidget
void initBasicStyleOption(QStyleOptionTabWidgetFrame *option) const
The QTabWidget class provides a stack of tabbed widgets.
Definition qtabwidget.h:21
QT_REQUIRE_CONFIG(thread)
QTabBar::Shape _q_tb_tabBarShapeFrom(QTabWidget::TabShape shape, QTabWidget::TabPosition position)
static QSize basicSize(bool horizontal, const QSize &lc, const QSize &rc, const QSize &s, const QSize &t)
QT_REQUIRE_CONFIG(tabwidget)