File indexing completed on 2026-10-06 09:28:19
0001
0002
0003
0004
0005 #ifndef QTABBAR_H
0006 #define QTABBAR_H
0007
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtWidgets/qwidget.h>
0010
0011 QT_REQUIRE_CONFIG(tabbar);
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 class QIcon;
0016 class QTabBarPrivate;
0017 class QStyleOptionTab;
0018
0019 class Q_WIDGETS_EXPORT QTabBar: public QWidget
0020 {
0021 Q_OBJECT
0022
0023 Q_PROPERTY(Shape shape READ shape WRITE setShape)
0024 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
0025 Q_PROPERTY(int count READ count)
0026 Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
0027 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
0028 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
0029 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
0030 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
0031 Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove
0032 WRITE setSelectionBehaviorOnRemove)
0033 Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
0034 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
0035 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
0036 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
0037 Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
0038
0039 public:
0040 explicit QTabBar(QWidget *parent = nullptr);
0041 ~QTabBar();
0042
0043 enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
0044 TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
0045 };
0046 Q_ENUM(Shape)
0047
0048 enum ButtonPosition {
0049 LeftSide,
0050 RightSide
0051 };
0052
0053 enum SelectionBehavior {
0054 SelectLeftTab,
0055 SelectRightTab,
0056 SelectPreviousTab
0057 };
0058
0059 Shape shape() const;
0060 void setShape(Shape shape);
0061
0062 int addTab(const QString &text);
0063 int addTab(const QIcon &icon, const QString &text);
0064
0065 int insertTab(int index, const QString &text);
0066 int insertTab(int index, const QIcon&icon, const QString &text);
0067
0068 void removeTab(int index);
0069 void moveTab(int from, int to);
0070
0071 bool isTabEnabled(int index) const;
0072 void setTabEnabled(int index, bool enabled);
0073
0074 bool isTabVisible(int index) const;
0075 void setTabVisible(int index, bool visible);
0076
0077 QString tabText(int index) const;
0078 void setTabText(int index, const QString &text);
0079
0080 QColor tabTextColor(int index) const;
0081 void setTabTextColor(int index, const QColor &color);
0082
0083 QIcon tabIcon(int index) const;
0084 void setTabIcon(int index, const QIcon &icon);
0085
0086 Qt::TextElideMode elideMode() const;
0087 void setElideMode(Qt::TextElideMode mode);
0088
0089 #if QT_CONFIG(tooltip)
0090 void setTabToolTip(int index, const QString &tip);
0091 QString tabToolTip(int index) const;
0092 #endif
0093
0094 #if QT_CONFIG(whatsthis)
0095 void setTabWhatsThis(int index, const QString &text);
0096 QString tabWhatsThis(int index) const;
0097 #endif
0098
0099 void setTabData(int index, const QVariant &data);
0100 QVariant tabData(int index) const;
0101
0102 QRect tabRect(int index) const;
0103 int tabAt(const QPoint &pos) const;
0104
0105 int currentIndex() const;
0106 int count() const;
0107
0108 QSize sizeHint() const override;
0109 QSize minimumSizeHint() const override;
0110
0111 void setDrawBase(bool drawTheBase);
0112 bool drawBase() const;
0113
0114 QSize iconSize() const;
0115 void setIconSize(const QSize &size);
0116
0117 bool usesScrollButtons() const;
0118 void setUsesScrollButtons(bool useButtons);
0119
0120 bool tabsClosable() const;
0121 void setTabsClosable(bool closable);
0122
0123 void setTabButton(int index, ButtonPosition position, QWidget *widget);
0124 QWidget *tabButton(int index, ButtonPosition position) const;
0125
0126 SelectionBehavior selectionBehaviorOnRemove() const;
0127 void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
0128
0129 bool expanding() const;
0130 void setExpanding(bool enabled);
0131
0132 bool isMovable() const;
0133 void setMovable(bool movable);
0134
0135 bool documentMode() const;
0136 void setDocumentMode(bool set);
0137
0138 bool autoHide() const;
0139 void setAutoHide(bool hide);
0140
0141 bool changeCurrentOnDrag() const;
0142 void setChangeCurrentOnDrag(bool change);
0143
0144 #if QT_CONFIG(accessibility)
0145 QString accessibleTabName(int index) const;
0146 void setAccessibleTabName(int index, const QString &name);
0147 #endif
0148
0149 public Q_SLOTS:
0150 void setCurrentIndex(int index);
0151
0152 Q_SIGNALS:
0153 void currentChanged(int index);
0154 void tabCloseRequested(int index);
0155 void tabMoved(int from, int to);
0156 void tabBarClicked(int index);
0157 void tabBarDoubleClicked(int index);
0158
0159 protected:
0160 virtual QSize tabSizeHint(int index) const;
0161 virtual QSize minimumTabSizeHint(int index) const;
0162 virtual void tabInserted(int index);
0163 virtual void tabRemoved(int index);
0164 virtual void tabLayoutChange();
0165
0166 bool event(QEvent *) override;
0167 void resizeEvent(QResizeEvent *) override;
0168 void showEvent(QShowEvent *) override;
0169 void hideEvent(QHideEvent *) override;
0170 void paintEvent(QPaintEvent *) override;
0171 void mousePressEvent(QMouseEvent *) override;
0172 void mouseMoveEvent(QMouseEvent *) override;
0173 void mouseReleaseEvent(QMouseEvent *) override;
0174 void mouseDoubleClickEvent(QMouseEvent *) override;
0175 #if QT_CONFIG(wheelevent)
0176 void wheelEvent(QWheelEvent *event) override;
0177 #endif
0178 void keyPressEvent(QKeyEvent *) override;
0179 void changeEvent(QEvent *) override;
0180 void timerEvent(QTimerEvent *event) override;
0181 virtual void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
0182
0183 #if QT_CONFIG(accessibility)
0184 friend class QAccessibleTabBar;
0185 #endif
0186 private:
0187 Q_DISABLE_COPY(QTabBar)
0188 Q_DECLARE_PRIVATE(QTabBar)
0189 };
0190
0191 QT_END_NAMESPACE
0192
0193 #endif