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 QTABWIDGET_H
5#define QTABWIDGET_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9#include <QtGui/qicon.h>
10
11QT_REQUIRE_CONFIG(tabwidget);
12
13QT_BEGIN_NAMESPACE
14
15class QTabBar;
16class QTabWidgetPrivate;
17class QStyleOptionTabWidgetFrame;
18
19class Q_WIDGETS_EXPORT QTabWidget : public QWidget
20{
21 Q_OBJECT
22 Q_PROPERTY(TabPosition tabPosition READ tabPosition WRITE setTabPosition)
23 Q_PROPERTY(TabShape tabShape READ tabShape WRITE setTabShape)
24 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
25 Q_PROPERTY(int count READ count)
26 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
27 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
28 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
29 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
30 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
31 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
32 Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide)
33
34public:
35 explicit QTabWidget(QWidget *parent = nullptr);
36 ~QTabWidget();
37
38 int addTab(QWidget *widget, const QString &);
39 int addTab(QWidget *widget, const QIcon& icon, const QString &label);
40
41 int insertTab(int index, QWidget *widget, const QString &);
42 int insertTab(int index, QWidget *widget, const QIcon& icon, const QString &label);
43
44 void removeTab(int index);
45
46 bool isTabEnabled(int index) const;
47 void setTabEnabled(int index, bool enabled);
48
49 bool isTabVisible(int index) const;
50 void setTabVisible(int index, bool visible);
51
52 QString tabText(int index) const;
53 void setTabText(int index, const QString &text);
54
55 QIcon tabIcon(int index) const;
56 void setTabIcon(int index, const QIcon & icon);
57
58#if QT_CONFIG(tooltip)
59 void setTabToolTip(int index, const QString & tip);
60 QString tabToolTip(int index) const;
61#endif
62
63#if QT_CONFIG(whatsthis)
64 void setTabWhatsThis(int index, const QString &text);
65 QString tabWhatsThis(int index) const;
66#endif
67
68 int currentIndex() const;
69 QWidget *currentWidget() const;
70 QWidget *widget(int index) const;
71 int indexOf(const QWidget *widget) const;
72 int count() const;
73
74 enum TabPosition { North, South, West, East };
75 Q_ENUM(TabPosition)
76 TabPosition tabPosition() const;
77 void setTabPosition(TabPosition position);
78
79 bool tabsClosable() const;
80 void setTabsClosable(bool closeable);
81
82 bool isMovable() const;
83 void setMovable(bool movable);
84
85 enum TabShape { Rounded, Triangular };
86 Q_ENUM(TabShape)
87 TabShape tabShape() const;
88 void setTabShape(TabShape s);
89
90 QSize sizeHint() const override;
91 QSize minimumSizeHint() const override;
92 int heightForWidth(int width) const override;
93 bool hasHeightForWidth() const override;
94
95 void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner);
96 QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
97
98 Qt::TextElideMode elideMode() const;
99 void setElideMode(Qt::TextElideMode mode);
100
101 QSize iconSize() const;
102 void setIconSize(const QSize &size);
103
104 bool usesScrollButtons() const;
105 void setUsesScrollButtons(bool useButtons);
106
107 bool documentMode() const;
108 void setDocumentMode(bool set);
109
110 bool tabBarAutoHide() const;
111 void setTabBarAutoHide(bool enabled);
112
113 void clear();
114
115 QTabBar* tabBar() const;
116
117public Q_SLOTS:
118 void setCurrentIndex(int index);
119 void setCurrentWidget(QWidget *widget);
120
121Q_SIGNALS:
122 void currentChanged(int index);
123 void tabCloseRequested(int index);
124 void tabBarClicked(int index);
125 void tabBarDoubleClicked(int index);
126
127protected:
128 virtual void tabInserted(int index);
129 virtual void tabRemoved(int index);
130
131 void showEvent(QShowEvent *) override;
132 void resizeEvent(QResizeEvent *) override;
133 void keyPressEvent(QKeyEvent *) override;
134 void paintEvent(QPaintEvent *) override;
135 void setTabBar(QTabBar *);
136 void changeEvent(QEvent *) override;
137 bool event(QEvent *) override;
138 virtual void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
139
140
141private:
142 Q_DECLARE_PRIVATE(QTabWidget)
143 Q_DISABLE_COPY(QTabWidget)
144 Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
145 Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
146 Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
147 void setUpLayout(bool = false);
148};
149
150QT_END_NAMESPACE
151
152#endif // QTABWIDGET_H
153

source code of qtbase/src/widgets/widgets/qtabwidget.h