CopperSpice API  1.9.1
QTabBar Class Reference

The QTabBar class provides a tab bar used in tabbed dialogs. More...

Inheritance diagram for QTabBar:
QWidget QObject QPaintDevice

Public Types

enum  ButtonPosition
 
enum  SelectionBehavior
 
enum  Shape
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void currentChanged (int index)
 
void tabBarClicked (int index)
 
void tabBarDoubleClicked (int index)
 
void tabCloseRequested (int index)
 
void tabMoved (int from, int to)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setCurrentIndex (int index)
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QTabBar (QWidget *parent=nullptr)
 
 ~QTabBar ()
 
int addTab (const QIcon &icon, const QString &text)
 
int addTab (const QString &text)
 
bool autoHide () const
 
bool changeCurrentOnDrag () const
 
int count () const
 
int currentIndex () const
 
bool documentMode () const
 
bool drawBase () const
 
Qt::TextElideMode elideMode () const
 
bool expanding () const
 
QSize iconSize () const
 
int insertTab (int index, const QIcon &icon, const QString &text)
 
int insertTab (int index, const QString &text)
 
bool isMovable () const
 
bool isTabEnabled (int index) const
 
QSize minimumSizeHint () const override
 
void moveTab (int from, int to)
 
void removeTab (int index)
 
SelectionBehavior selectionBehaviorOnRemove () const
 
void setAutoHide (bool hide)
 
void setChangeCurrentOnDrag (bool change)
 
void setDocumentMode (bool set)
 
void setDrawBase (bool drawTheBase)
 
void setElideMode (Qt::TextElideMode value)
 
void setExpanding (bool enable)
 
void setIconSize (const QSize &size)
 
void setMovable (bool movable)
 
void setSelectionBehaviorOnRemove (SelectionBehavior behavior)
 
void setShape (Shape shape)
 
void setTabButton (int index, ButtonPosition position, QWidget *widget)
 
void setTabData (int index, const QVariant &data)
 
void setTabEnabled (int index, bool enable)
 
void setTabIcon (int index, const QIcon &icon)
 
void setTabsClosable (bool closeable)
 
void setTabText (int index, const QString &text)
 
void setTabTextColor (int index, const QColor &color)
 
void setTabToolTip (int index, const QString &tip)
 
void setTabWhatsThis (int index, const QString &text)
 
void setUsesScrollButtons (bool useButtons)
 
Shape shape () const
 
QSize sizeHint () const override
 
int tabAt (const QPoint &pos) const
 
QWidgettabButton (int index, ButtonPosition position) const
 
QVariant tabData (int index) const
 
QIcon tabIcon (int index) const
 
QRect tabRect (int index) const
 
bool tabsClosable () const
 
QString tabText (int index) const
 
QColor tabTextColor (int index) const
 
QString tabToolTip (int index) const
 
QString tabWhatsThis (int index) const
 
bool usesScrollButtons () const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
virtual int heightForWidth (int width) const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void changeEvent (QEvent *event) override
 
bool event (QEvent *event) override
 
void hideEvent (QHideEvent *event) override
 
void initStyleOption (QStyleOptionTab *option, int tabIndex) const
 
void keyPressEvent (QKeyEvent *event) override
 
virtual QSize minimumTabSizeHint (int index) const
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void showEvent (QShowEvent *event) override
 
virtual void tabInserted (int index)
 
virtual void tabLayoutChange ()
 
virtual void tabRemoved (int index)
 
virtual QSize tabSizeHint (int index) const
 
void timerEvent (QTimerEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
virtual void focusInEvent (QFocusEvent *event)
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
virtual void focusOutEvent (QFocusEvent *event)
 
bool focusPreviousChild ()
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void tabletEvent (QTabletEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 autoHide
 
 changeCurrentOnDrag
 
 count
 
 currentIndex
 
 documentMode
 
 drawBase
 
 elideMode
 
 expanding
 
 iconSize
 
 movable
 
 selectionBehaviorOnRemove
 
 shape
 
 tabsClosable
 
 usesScrollButtons
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QTabBar class provides a tab bar used in tabbed dialogs. This class draws the tabs using one of the predefined shapes and emits a signal when a tab is selected. It can be subclassed to tailor the look and feel. CopperSpice provides a ready-made QTabWidget.

Each tab has a tabText(), an optional tabIcon(), an optional tabToolTip(), optional tabWhatsThis() and optional tabData(). The tab's attributes can be changed with setTabText(), setTabIcon(), setTabToolTip(), setTabWhatsThis and setTabData(). Each tabs can be enabled or disabled individually with setTabEnabled().

Each tab can display text in a distinct color. The current text color for a tab can be found with the tabTextColor() function. Set the text color for a particular tab with setTabTextColor().

Tabs are added using addTab(), or inserted at particular positions using insertTab(). The total number of tabs is given by count(). Tabs can be removed from the tab bar with removeTab(). Combining removeTab() and insertTab() allows you to move tabs to different positions.

The shape property defines the tabs' appearance. The choice of shape is a matter of taste, although tab dialogs (for preferences and similar) invariably use RoundedNorth. Tab controls in windows other than dialogs almost always use either RoundedSouth or TriangularSouth. Many spreadsheets and other tab controls in which all the pages are essentially similar use TriangularSouth, whereas RoundedSouth is used mostly when the pages are different (e.g. a multi-page tool palette). The default in QTabBar is RoundedNorth.

The most important part of QTabBar's API is the currentChanged() signal. This is emitted whenever the current tab changes (even at startup, when the current tab changes from 'none'). There is also a slot, setCurrentIndex(), which can be used to select a tab programmatically. The function currentIndex() returns the index of the current tab, count holds the number of tabs.

QTabBar creates automatic mnemonic keys in the manner of QAbstractButton; e.g. if a tab's label is "&Graphics", Alt+G becomes a shortcut key for switching to that tab.

The following virtual functions may need to be reimplemented in order to tailor the look and feel or store extra data with each tab:

For subclasses, you might also need the tabRect() functions which returns the visual geometry of a single tab.

Screenshot of a Fusion style tab bar A tab bar shown in the Fusion widget style.
Screenshot of a truncated Fusion tab bar A truncated tab bar shown in the Fusion widget style.
See also
QTabWidget

Member Enumeration Documentation

This enum type lists the location of the widget on a tab.

ConstantValueDescription
QTabBar::LeftSide0Left side of the tab.
QTabBar::RightSide1Right side of the tab.

This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also the current tab.

ConstantValueDescription
QTabBar::SelectLeftTab0Select the tab to the left of the one being removed.
QTabBar::SelectRightTab1Select the tab to the right of the one being removed.
QTabBar::SelectPreviousTab2Select the previously selected tab.

This enum type lists the built-in shapes supported by QTabBar. Treat these as hints as some styles may not render some of the shapes. However, position should be honored.

ConstantValueDescription
QTabBar::RoundedNorth0The normal rounded look above the pages
QTabBar::RoundedSouth1The normal rounded look below the pages
QTabBar::RoundedWest2The normal rounded look on the left side of the pages
QTabBar::RoundedEast3The normal rounded look on the right side the pages
QTabBar::TriangularNorth4Triangular tabs above the pages.
QTabBar::TriangularSouth5Triangular tabs similar to those used in the Excel spreadsheet, for example
QTabBar::TriangularWest6 Triangular tabs on the left of the pages.
QTabBar::TriangularEast7 Triangular tabs on the right of the pages.

Constructor & Destructor Documentation

QTabBar::QTabBar ( QWidget parent = nullptr)
explicit

Creates a new tab bar with the given parent.

QTabBar::~QTabBar ( )

Destroys the tab bar.

Method Documentation

int QTabBar::addTab ( const QIcon icon,
const QString text 
)

Adds a new tab with the given icon and text. Returns the new tab's index.

int QTabBar::addTab ( const QString text)

Adds a new tab with the given text. Returns the new tab's index.

bool QTabBar::autoHide ( ) const

Returns the value of the property.

bool QTabBar::changeCurrentOnDrag ( ) const

Returns the value of the property.

void QTabBar::changeEvent ( QEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::changeEvent()

int QTabBar::count ( ) const

Returns the value of the property.

void QTabBar::currentChanged ( int  index)
signal

This signal is emitted when the tab bar's current tab changes. The new current has the given index, or -1 if there is not a new one (for example, if there are no tab in the QTabBar)

int QTabBar::currentIndex ( ) const

Returns the value of the property.

bool QTabBar::documentMode ( ) const

Returns the value of the property.

bool QTabBar::drawBase ( ) const

Returns the value of the property.

Qt::TextElideMode QTabBar::elideMode ( ) const

Returns the value of the property.

bool QTabBar::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

bool QTabBar::expanding ( ) const

Returns the value of the property.

void QTabBar::hideEvent ( QHideEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::hideEvent()

QSize QTabBar::iconSize ( ) const

Returns the value of the property.

void QTabBar::initStyleOption ( QStyleOptionTab option,
int  tabIndex 
) const
protected

Initialize option with the values from the tab at tabIndex. This method is useful for subclasses when they need a QStyleOptionTab but do not want to fill in all the information themselves.

See also
QStyleOption::initFrom(), QTabWidget::initStyleOption()
int QTabBar::insertTab ( int  index,
const QIcon icon,
const QString text 
)

Inserts a new tab with the given icon and text at position index. Returns the new tab's index.

If index is out of range, the new tab is appended. If the QTabBar was empty before this function is called, the inserted tab becomes the current tab. Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current tab.

int QTabBar::insertTab ( int  index,
const QString text 
)

Inserts a new tab with the given text at position index. If index is out of range the new tab is appended. Returns the new tab's index.

bool QTabBar::isMovable ( ) const

Returns the value of the property.

bool QTabBar::isTabEnabled ( int  index) const

Returns true if the tab at position index is enabled, otherwise returns false.

void QTabBar::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyPressEvent()

QSize QTabBar::minimumSizeHint ( ) const
overridevirtual

Reimplemented from QWidget::minimumSizeHint()

QSize QTabBar::minimumTabSizeHint ( int  index) const
protectedvirtual

Returns the minimum tab size hint for the tab at position index.

void QTabBar::mouseMoveEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseMoveEvent()

void QTabBar::mousePressEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mousePressEvent()

void QTabBar::mouseReleaseEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseReleaseEvent()

void QTabBar::moveTab ( int  from,
int  to 
)

Moves the item at index position from to index position to.

See also
tabMoved(), tabLayoutChange()
void QTabBar::paintEvent ( QPaintEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::paintEvent()

void QTabBar::removeTab ( int  index)

Removes the tab at position index.

See also
SelectionBehavior
void QTabBar::resizeEvent ( QResizeEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::resizeEvent()

SelectionBehavior QTabBar::selectionBehaviorOnRemove ( ) const

Returns the value of the property.

void QTabBar::setAutoHide ( bool  hide)

Sets the value of the property to hide.

void QTabBar::setChangeCurrentOnDrag ( bool  change)

Sets the value of the property to change.

void QTabBar::setCurrentIndex ( int  index)
slot

Sets the value of the property to index.

void QTabBar::setDocumentMode ( bool  set)

Sets the value of the property to set.

void QTabBar::setDrawBase ( bool  drawTheBase)

Sets the value of the property to drawTheBase.

void QTabBar::setElideMode ( Qt::TextElideMode  value)

Sets the value of the property to value.

void QTabBar::setExpanding ( bool  enable)

Sets the value of the property to enable.

void QTabBar::setIconSize ( const QSize size)

Sets the value of the property to size.

void QTabBar::setMovable ( bool  movable)

Sets the value of the property to moveable.

void QTabBar::setSelectionBehaviorOnRemove ( SelectionBehavior  behavior)

Sets the value of the property to behavior.

void QTabBar::setShape ( Shape  shape)

Sets the value of the property to shape.

void QTabBar::setTabButton ( int  index,
ButtonPosition  position,
QWidget widget 
)

Sets widget on the tab index. The widget is placed on the left or right hand side depending upon the position. Any previously set widget in position is hidden.

The QTabBar takes ownership of the widget.

See also
tabButton(), tabsClosable()
void QTabBar::setTabData ( int  index,
const QVariant data 
)

Sets the data of the tab at position index to data.

See also
tabData()
void QTabBar::setTabEnabled ( int  index,
bool  enable 
)

If enabled is true then the tab at position index is enabled, otherwise the item at position indexis disabled.

See also
isTabEnabled()
void QTabBar::setTabIcon ( int  index,
const QIcon icon 
)

Sets the icon of the tab at position index to icon.

See also
tabIcon()
void QTabBar::setTabsClosable ( bool  closeable)

Sets the value of the property to closeable.

void QTabBar::setTabText ( int  index,
const QString text 
)

Sets the text of the tab at position index to text.

See also
tabText()
void QTabBar::setTabTextColor ( int  index,
const QColor color 
)

Sets the color of the text in the tab with the given index to the specified color. If an invalid color is specified, the tab will use the QTabBar foreground role instead.

See also
tabTextColor()
void QTabBar::setTabToolTip ( int  index,
const QString tip 
)

Sets the tool tip of the tab at position index to tip.

See also
tabToolTip()
void QTabBar::setTabWhatsThis ( int  index,
const QString text 
)

Sets the What's This help text of the tab at position index to text.

See also
tabWhatsThis()
void QTabBar::setUsesScrollButtons ( bool  useButtons)

Sets the value of the property to useButtons.

Shape QTabBar::shape ( ) const

Returns the value of the property.

void QTabBar::showEvent ( QShowEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::showEvent()

QSize QTabBar::sizeHint ( ) const
overridevirtual

Reimplemented from QWidget::sizeHint()

int QTabBar::tabAt ( const QPoint pos) const

Returns the index of the tab that covers pos or -1 if no tab covers pos.

void QTabBar::tabBarClicked ( int  index)
signal

This signal is emitted when the user clicks on a tab. The index refers to the tab which was clicked or -1 if no tab is under the cursor.

void QTabBar::tabBarDoubleClicked ( int  index)
signal

This signal is emitted when the user double clicks on a tab at an index. The index refers to the tab which was clicked or -1 if no tab is under the cursor.

QWidget * QTabBar::tabButton ( int  index,
ButtonPosition  position 
) const

Returns the widget set at index and position or a nullptr if one is not set.

See also
setTabButton()
void QTabBar::tabCloseRequested ( int  index)
signal

This signal is emitted when the close button on a tab is clicked. The index is the index that should be removed.

See also
setTabsClosable()
QVariant QTabBar::tabData ( int  index) const

Returns the data of the tab at position index, or a null variant if index is out of range.

See also
setTabData()
QIcon QTabBar::tabIcon ( int  index) const

Returns the icon of the tab at position index, or a null icon if index is out of range.

See also
setTabIcon()
void QTabBar::tabInserted ( int  index)
protectedvirtual

This virtual handler is called after a new tab was added or inserted at position index.

See also
tabRemoved()
void QTabBar::tabLayoutChange ( )
protectedvirtual

This method is called whenever the tab layout changes.

See also
tabRect()
void QTabBar::tabMoved ( int  from,
int  to 
)
signal

This signal is emitted when the tab has moved the tab at index position from to index position to. QTabWidget will automatically move the page when this signal is emitted from its tab bar.

See also
moveTab()
QRect QTabBar::tabRect ( int  index) const

Returns the visual rectangle of the tab at position index, or a null rectangle if index is out of range.

void QTabBar::tabRemoved ( int  index)
protectedvirtual

This method is called after a tab was removed from position index.

See also
tabInserted()
bool QTabBar::tabsClosable ( ) const

Returns the value of the property.

QSize QTabBar::tabSizeHint ( int  index) const
protectedvirtual

Returns the size hint for the tab at position index.

QString QTabBar::tabText ( int  index) const

Returns the text of the tab at position index, or an empty string if index is out of range.

See also
setTabText()
QColor QTabBar::tabTextColor ( int  index) const

Returns the text color of the tab with the given index, or an invalid color if index is out of range.

See also
setTabTextColor()
QString QTabBar::tabToolTip ( int  index) const

Returns the tool tip of the tab at position index, or an empty string if index is out of range.

See also
setTabToolTip()
QString QTabBar::tabWhatsThis ( int  index) const

Returns the What's This help text of the tab at position index, or an empty string if index is out of range.

See also
setTabWhatsThis()
void QTabBar::timerEvent ( QTimerEvent event)
overrideprotected

Reimplemented from QWidget::timerEvent()

bool QTabBar::usesScrollButtons ( ) const

Returns the value of the property.

void QTabBar::wheelEvent ( QWheelEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::wheelEvent()

Property Documentation

QTabBar::autoHide

If true, the tab bar is automatically hidden when it contains less than 2 tabs. By default this property is false.

See also
QWidget::visible
PropertiesClass Methods
read autoHide
write setAutoHide
QTabBar::changeCurrentOnDrag

If true then the current tab is automatically changed when dragging over the tabbar. By default this property is false.

You should also set acceptDrops property to true to make this feature work.

PropertiesClass Methods
read changeCurrentOnDrag
write setChangeCurrentOnDrag
QTabBar::count

This property holds the number of tabs in the tab bar.

PropertiesClass Methods
read count
QTabBar::currentIndex

This property holds the index of the tab bar's visible tab. The current index is -1 if there is no current tab.

PropertiesClass Methods
read currentIndex
write setCurrentIndex
notify currentChanged
QTabBar::documentMode

This property holds whether or not the tab bar is rendered in a mode suitable for the main window.

This property is used as a hint for styles to draw the tabs in a different way then they would normally look in a tab widget. On Mac OS X this will look similar to the tabs in Safari or Leopard's Terminal.app.

See also
QTabWidget::documentMode
PropertiesClass Methods
read documentMode
write setDocumentMode
QTabBar::drawBase

This property defines whether or not tab bar should draw its base. If true then QTabBar draws a base in relation to the styles overlap. Otherwise only the tabs are drawn.

See also
QStyle::pixelMetric(), QStyle::PixelMetric
PropertiesClass Methods
read drawBase
write setDrawBase
QTabBar::elideMode

This property holds how to elide text in the tab bar. It controls how items are elided when there is not enough space to show them for a given tab bar size.

By default the value is style dependent.

See also
QTabWidget::elideMode, QTabBar::usesScrollButtons, QStyle::StyleHint
PropertiesClass Methods
read elideMode
write setElideMode
QTabBar::expanding

This property holds when expanding is true QTabBar will expand the tabs to use the empty space.

By default the value is true.

See also
QTabWidget::documentMode
PropertiesClass Methods
read expanding
write setExpanding
QTabBar::iconSize

This property holds the size for icons in the tab bar. The default value is style-dependent. iconSize is a maximum size; icons that are smaller are not scaled up.

See also
QTabWidget::iconSize
PropertiesClass Methods
read iconSize
write setIconSize
QTabBar::movable

This property holds this property holds whether the user can move the tabs within the tabbar area.

By default, this property is false;

PropertiesClass Methods
read isMovable
write setMovable
QTabBar::selectionBehaviorOnRemove

This property holds what tab should be set as current when removeTab is called if the removed tab is also the current tab.

By default the value is SelectRightTab.

See also
removeTab()
PropertiesClass Methods
read selectionBehaviorOnRemove
write setSelectionBehaviorOnRemove
QTabBar::shape

This property holds the shape of the tabs in the tab bar.

Possible values for this property are described by the Shape enum.

PropertiesClass Methods
read shape
write setShape
QTabBar::tabsClosable

This property holds whether or not a tab bar should place close buttons on each tab.

When tabsClosable is set to true a close button will appear on the tab on either the left or right hand side depending upon the style. When the button is clicked the tab the signal tabCloseRequested will be emitted.

By default the value is false.

See also
setTabButton(), tabRemoved()
PropertiesClass Methods
read tabsClosable
write setTabsClosable
QTabBar::usesScrollButtons

This property holds whether or not a tab bar should use buttons to scroll tabs when it has many tabs. When there are too many tabs in a tab bar for its size, the tab bar can either choose to expand its size or to add buttons that allow you to scroll through the tabs.

By default the value is style dependent.

See also
QTabBar::elideMode, QTabWidget::usesScrollButtons, QStyle::StyleHint
PropertiesClass Methods
read usesScrollButtons
write setUsesScrollButtons