|  | Home · All Classes · Modules

# QTabBar Class Reference
[QtGui module]

The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs. More...

Inherits QWidget.

### Types

- enum ButtonPosition { LeftSide, RightSide }
- enum SelectionBehavior { SelectLeftTab, SelectRightTab, SelectPreviousTab }
- enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, ..., TriangularEast }

### Methods

- __init__ (self, QWidget parent = None)
- int addTab (self, QString)
- int addTab (self, QIcon, QString)
- changeEvent (self, QEvent)
- int count (self)
- int currentIndex (self)
- bool documentMode (self)
- bool drawBase (self)
- Qt.TextElideMode elideMode (self)
- bool event (self, QEvent)
- bool expanding (self)
- hideEvent (self, QHideEvent)
- QSize iconSize (self)
- initStyleOption (self, QStyleOptionTab, int)
- int insertTab (self, int, QString)
- int insertTab (self, int, QIcon, QString)
- bool isMovable (self)
- bool isTabEnabled (self, int)
- keyPressEvent (self, QKeyEvent)
- QSize minimumSizeHint (self)
- mouseMoveEvent (self, QMouseEvent)
- mousePressEvent (self, QMouseEvent)
- mouseReleaseEvent (self, QMouseEvent)
- moveTab (self, int, int)
- paintEvent (self, QPaintEvent)
- removeTab (self, int)
- resizeEvent (self, QResizeEvent)
- SelectionBehavior selectionBehaviorOnRemove (self)
- setCurrentIndex (self, int)
- setDocumentMode (self, bool)
- setDrawBase (self, bool)
- setElideMode (self, Qt.TextElideMode)
- setExpanding (self, bool)
- setIconSize (self, QSize)
- setMovable (self, bool)
- setSelectionBehaviorOnRemove (self, SelectionBehavior)
- setShape (self, Shape)
- setTabButton (self, int, ButtonPosition, QWidget)
- setTabData (self, int, QVariant)
- setTabEnabled (self, int, bool)
- setTabIcon (self, int, QIcon)
- setTabsClosable (self, bool)
- setTabText (self, int, QString)
- setTabTextColor (self, int, QColor)
- setTabToolTip (self, int, QString)
- setTabWhatsThis (self, int, QString)
- setUsesScrollButtons (self, bool)
- Shape shape (self)
- showEvent (self, QShowEvent)
- QSize sizeHint (self)
- int tabAt (self, QPoint)
- QWidget tabButton (self, int, ButtonPosition)
- QVariant tabData (self, int)
- QIcon tabIcon (self, int)
- tabInserted (self, int)
- tabLayoutChange (self)
- QRect tabRect (self, int)
- tabRemoved (self, int)
- bool tabsClosable (self)
- QSize tabSizeHint (self, int)
- QString tabText (self, int)
- QColor tabTextColor (self, int)
- QString tabToolTip (self, int)
- QString tabWhatsThis (self, int)
- bool usesScrollButtons (self)
- wheelEvent (self, QWheelEvent)

### Special Methods

- __len__ (self)

### Qt Signals

- void currentChanged (int)
- void tabCloseRequested (int)
- void tabMoved (int,int)

## Detailed Description

The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs.

QTabBar is straightforward to use; it 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. Qt also provides a ready-made QTabWidget.

Each tab has a tabText(), an optional tabIcon(), an optional tabToolTip(), optional tabWhatsThis() and optional tabData(). The tabs'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:

- tabSizeHint() calcuates the size of a tab.
- tabInserted() notifies that a new tab was added.
- tabRemoved() notifies that a tab was removed.
- tabLayoutChange() notifies that the tabs have been re-laid out.
- paintEvent() paints all tabs.

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

| A tab bar shown in the Plastique widget style.
| A truncated tab bar shown in the Plastique widget style.

## Type Documentation

### QTabBar.ButtonPosition

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

Constant | Value | Description
--- | --- | ---
`QTabBar.LeftSide` | `0` | Left side of the tab.
`QTabBar.RightSide` | `1` | Right side of the tab.

This enum was introduced in Qt 4.5.

### QTabBar.SelectionBehavior

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

Constant | Value | Description
--- | --- | ---
`QTabBar.SelectLeftTab` | `0` | Select the tab to the left of the one being removed.
`QTabBar.SelectRightTab` | `1` | Select the tab to the right of the one being removed.
`QTabBar.SelectPreviousTab` | `2` | Select the previously selected tab.

This enum was introduced in Qt 4.5.

### QTabBar.Shape

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.

Constant | Value | Description
--- | --- | ---
`QTabBar.RoundedNorth` | `0` | The normal rounded look above the pages
`QTabBar.RoundedSouth` | `1` | The normal rounded look below the pages
`QTabBar.RoundedWest` | `2` | The normal rounded look on the left side of the pages
`QTabBar.RoundedEast` | `3` | The normal rounded look on the right side the pages
`QTabBar.TriangularNorth` | `4` | Triangular tabs above the pages.
`QTabBar.TriangularSouth` | `5` | Triangular tabs similar to those used in the Excel spreadsheet, for example
`QTabBar.TriangularWest` | `6` | Triangular tabs on the left of the pages.
`QTabBar.TriangularEast` | `7` | Triangular tabs on the right of the pages.

## Method Documentation

### QTabBar.__init__ (self, QWidget parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Creates a new tab bar with the given parent.

### int QTabBar.addTab (self, QString)

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

### int QTabBar.addTab (self, QIcon, QString)

This is an overloaded function.

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

### QTabBar.changeEvent (self, QEvent)

Reimplemented from QWidget.changeEvent().

### int QTabBar.count (self)

### int QTabBar.currentIndex (self)

### bool QTabBar.documentMode (self)

### bool QTabBar.drawBase (self)

### Qt.TextElideMode QTabBar.elideMode (self)

### bool QTabBar.event (self, QEvent)

Reimplemented from QObject.event().

### bool QTabBar.expanding (self)

### QTabBar.hideEvent (self, QHideEvent)

Reimplemented from QWidget.hideEvent().

### QSize QTabBar.iconSize (self)

### QTabBar.initStyleOption (self, QStyleOptionTab, int)

Initialize option with the values from the tab at tabIndex. This method is useful for subclasses when they need a QStyleOptionTab, QStyleOptionTabV2, or QStyleOptionTabV3 but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionTab and fill in the additional values for a QStyleOptionTabV2 and QStyleOptionTabV3.

See also QStyleOption.initFrom() and QTabWidget.initStyleOption().

### int QTabBar.insertTab (self, int, QString)

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

### int QTabBar.insertTab (self, int, QIcon, QString)

This is an overloaded function.

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

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.

### bool QTabBar.isMovable (self)

### bool QTabBar.isTabEnabled (self, int)

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

### QTabBar.keyPressEvent (self, QKeyEvent)

Reimplemented from QWidget.keyPressEvent().

### QSize QTabBar.minimumSizeHint (self)

Reimplemented from QWidget.minimumSizeHint().

### QTabBar.mouseMoveEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseMoveEvent().

### QTabBar.mousePressEvent (self, QMouseEvent)

Reimplemented from QWidget.mousePressEvent().

### QTabBar.mouseReleaseEvent (self, QMouseEvent)

Reimplemented from QWidget.mouseReleaseEvent().

### QTabBar.moveTab (self, int, int)

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

This function was introduced in Qt 4.5.

See also tabMoved() and tabLayoutChange().

### QTabBar.paintEvent (self, QPaintEvent)

Reimplemented from QWidget.paintEvent().

### QTabBar.removeTab (self, int)

Removes the tab at position index.

See also SelectionBehavior.

### QTabBar.resizeEvent (self, QResizeEvent)

Reimplemented from QWidget.resizeEvent().

### SelectionBehavior QTabBar.selectionBehaviorOnRemove (self)

### QTabBar.setCurrentIndex (self, int)

This method is also a Qt slot with the C++ signature `void setCurrentIndex(int)`.

### QTabBar.setDocumentMode (self, bool)

### QTabBar.setDrawBase (self, bool)

### QTabBar.setElideMode (self, Qt.TextElideMode)

### QTabBar.setExpanding (self, bool)

### QTabBar.setIconSize (self, QSize)

### QTabBar.setMovable (self, bool)

### QTabBar.setSelectionBehaviorOnRemove (self, SelectionBehavior)

### QTabBar.setShape (self, Shape)

### QTabBar.setTabButton (self, int, ButtonPosition, QWidget)

The QWidget argument has it's ownership transferred to Qt.

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 tab bar will take ownership of the widget and so all widgets set here will be deleted by the tab bar when it is destroyed unless you separately reparent the widget after setting some other widget (or 0).

This function was introduced in Qt 4.5.

See also tabButton() and tabsClosable().

### QTabBar.setTabData (self, int, QVariant)

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

See also tabData().

### QTabBar.setTabEnabled (self, int, bool)

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

See also isTabEnabled().

### QTabBar.setTabIcon (self, int, QIcon)

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

See also tabIcon().

### QTabBar.setTabsClosable (self, bool)

### QTabBar.setTabText (self, int, QString)

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

See also tabText().

### QTabBar.setTabTextColor (self, int, QColor)

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().

### QTabBar.setTabToolTip (self, int, QString)

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

See also tabToolTip().

### QTabBar.setTabWhatsThis (self, int, QString)

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

This function was introduced in Qt 4.1.

See also tabWhatsThis().

### QTabBar.setUsesScrollButtons (self, bool)

### Shape QTabBar.shape (self)

### QTabBar.showEvent (self, QShowEvent)

Reimplemented from QWidget.showEvent().

### QSize QTabBar.sizeHint (self)

Reimplemented from QWidget.sizeHint().

### int QTabBar.tabAt (self, QPoint)

Returns the index of the tab that covers position or -1 if no tab covers position;

This function was introduced in Qt 4.3.

### QWidget QTabBar.tabButton (self, int, ButtonPosition)

Returns the widget set a tab index and position or 0 if one is not set.

See also setTabButton().

### QVariant QTabBar.tabData (self, int)

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 (self, int)

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

See also setTabIcon().

### QTabBar.tabInserted (self, int)

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

See also tabRemoved().

### QTabBar.tabLayoutChange (self)

This virtual handler is called whenever the tab layout changes.

See also tabRect().

### QRect QTabBar.tabRect (self, int)

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

### QTabBar.tabRemoved (self, int)

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

See also tabInserted().

### bool QTabBar.tabsClosable (self)

### QSize QTabBar.tabSizeHint (self, int)

Returns the size hint for the tab at position index.

### QString QTabBar.tabText (self, int)

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 (self, int)

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

See also setTabTextColor().

### QString QTabBar.tabToolTip (self, int)

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 (self, int)

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

This function was introduced in Qt 4.1.

See also setTabWhatsThis().

### bool QTabBar.usesScrollButtons (self)

### QTabBar.wheelEvent (self, QWheelEvent)

Reimplemented from QWidget.wheelEvent().

### QTabBar.__len__ (self)

## Qt Signal Documentation

### void currentChanged (int)

This is the default overload of this signal.

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

### void tabCloseRequested (int)

This is the default overload of this signal.

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

This function was introduced in Qt 4.5.

See also setTabsClosable().

### void tabMoved (int,int)

This is the default overload of this signal.

This signal is emitted when the tab has moved the tab at index position from to index position to.

note: QTabWidget will automatically move the page when this signal is emitted from its tab bar.

This function was introduced in Qt 4.5.

See also moveTab().