QTabBar

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

Inheritance diagram of PySide6.QtWidgets.QTabBar

Synopsis

Functions

Virtual functions

Detailed Description

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 , an optional , an optional , optional and optional . The tabs’s attributes can be changed with , , , setTabWhatsThis and . Each tabs can be enabled or disabled individually with .

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

Tabs are added using , or inserted at particular positions using . The total number of tabs is given by count() . Tabs can be removed from the tab bar with . Combining and 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:

  • calcuates the size of a tab.

  • notifies that a new tab was added.

  • notifies that a tab was removed.

  • notifies that the tabs have been re-laid out.

  • paints all tabs.

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

fusion-tabbar1

A tab bar shown in the Fusion widget style .

fusion-tabbar-truncated2

A truncated tab bar shown in the Fusion widget style.

See also

QTabWidget

class PySide6.QtWidgets.QTabBar([parent=None])
Parameters

parentPySide6.QtWidgets.QWidget

PySide6.QtWidgets.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

Description

QTabBar.RoundedNorth

The normal rounded look above the pages

QTabBar.RoundedSouth

The normal rounded look below the pages

QTabBar.RoundedWest

The normal rounded look on the left side of the pages

QTabBar.RoundedEast

The normal rounded look on the right side the pages

QTabBar.TriangularNorth

Triangular tabs above the pages.

QTabBar.TriangularSouth

Triangular tabs similar to those used in the Excel spreadsheet, for example

QTabBar.TriangularWest

Triangular tabs on the left of the pages.

QTabBar.TriangularEast

Triangular tabs on the right of the pages.

PySide6.QtWidgets.QTabBar.ButtonPosition

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

Constant

Description

QTabBar.LeftSide

Left side of the tab.

QTabBar.RightSide

Right side of the tab.

PySide6.QtWidgets.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

Description

QTabBar.SelectLeftTab

Select the tab to the left of the one being removed.

QTabBar.SelectRightTab

Select the tab to the right of the one being removed.

QTabBar.SelectPreviousTab

Select the previously selected tab.

PySide6.QtWidgets.QTabBar.accessibleTabName(index)
Parameters

index – int

Return type

str

PySide6.QtWidgets.QTabBar.addTab(icon, text)
Parameters
Return type

int

PySide6.QtWidgets.QTabBar.addTab(text)
Parameters

text – str

Return type

int

PySide6.QtWidgets.QTabBar.autoHide()
Return type

bool

See also

setAutoHide()

PySide6.QtWidgets.QTabBar.changeCurrentOnDrag()
Return type

bool

PySide6.QtWidgets.QTabBar.count()
Return type

int

PySide6.QtWidgets.QTabBar.currentChanged(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.currentIndex()
Return type

int

PySide6.QtWidgets.QTabBar.documentMode()
Return type

bool

PySide6.QtWidgets.QTabBar.drawBase()
Return type

bool

See also

setDrawBase()

PySide6.QtWidgets.QTabBar.elideMode()
Return type

TextElideMode

See also

setElideMode()

PySide6.QtWidgets.QTabBar.expanding()
Return type

bool

See also

setExpanding()

PySide6.QtWidgets.QTabBar.iconSize()
Return type

PySide6.QtCore.QSize

See also

setIconSize()

PySide6.QtWidgets.QTabBar.initStyleOption(option, tabIndex)
Parameters
PySide6.QtWidgets.QTabBar.insertTab(index, text)
Parameters
  • index – int

  • text – str

Return type

int

PySide6.QtWidgets.QTabBar.insertTab(index, icon, text)
Parameters
Return type

int

PySide6.QtWidgets.QTabBar.isMovable()
Return type

bool

PySide6.QtWidgets.QTabBar.isTabEnabled(index)
Parameters

index – int

Return type

bool

PySide6.QtWidgets.QTabBar.isTabVisible(index)
Parameters

index – int

Return type

bool

PySide6.QtWidgets.QTabBar.minimumTabSizeHint(index)
Parameters

index – int

Return type

PySide6.QtCore.QSize

PySide6.QtWidgets.QTabBar.moveTab(from, to)
Parameters
  • from – int

  • to – int

PySide6.QtWidgets.QTabBar.removeTab(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.selectionBehaviorOnRemove()
Return type

SelectionBehavior

PySide6.QtWidgets.QTabBar.setAccessibleTabName(index, name)
Parameters
  • index – int

  • name – str

PySide6.QtWidgets.QTabBar.setAutoHide(hide)
Parameters

hide – bool

See also

autoHide()

PySide6.QtWidgets.QTabBar.setChangeCurrentOnDrag(change)
Parameters

change – bool

PySide6.QtWidgets.QTabBar.setCurrentIndex(index)
Parameters

index – int

See also

currentIndex()

PySide6.QtWidgets.QTabBar.setDocumentMode(set)
Parameters

set – bool

See also

documentMode()

PySide6.QtWidgets.QTabBar.setDrawBase(drawTheBase)
Parameters

drawTheBase – bool

See also

drawBase()

PySide6.QtWidgets.QTabBar.setElideMode(mode)
Parameters

modeTextElideMode

See also

elideMode()

PySide6.QtWidgets.QTabBar.setExpanding(enabled)
Parameters

enabled – bool

See also

expanding()

PySide6.QtWidgets.QTabBar.setIconSize(size)
Parameters

sizePySide6.QtCore.QSize

See also

iconSize()

PySide6.QtWidgets.QTabBar.setMovable(movable)
Parameters

movable – bool

See also

isMovable()

PySide6.QtWidgets.QTabBar.setSelectionBehaviorOnRemove(behavior)
Parameters

behaviorSelectionBehavior

PySide6.QtWidgets.QTabBar.setShape(shape)
Parameters

shapeShape

See also

shape()

PySide6.QtWidgets.QTabBar.setTabButton(index, position, widget)
Parameters
PySide6.QtWidgets.QTabBar.setTabData(index, data)
Parameters
  • index – int

  • data – object

PySide6.QtWidgets.QTabBar.setTabEnabled(index, enabled)
Parameters
  • index – int

  • enabled – bool

PySide6.QtWidgets.QTabBar.setTabIcon(index, icon)
Parameters
PySide6.QtWidgets.QTabBar.setTabText(index, text)
Parameters
  • index – int

  • text – str

PySide6.QtWidgets.QTabBar.setTabTextColor(index, color)
Parameters
PySide6.QtWidgets.QTabBar.setTabToolTip(index, tip)
Parameters
  • index – int

  • tip – str

PySide6.QtWidgets.QTabBar.setTabVisible(index, visible)
Parameters
  • index – int

  • visible – bool

PySide6.QtWidgets.QTabBar.setTabWhatsThis(index, text)
Parameters
  • index – int

  • text – str

PySide6.QtWidgets.QTabBar.setTabsClosable(closable)
Parameters

closable – bool

See also

tabsClosable()

PySide6.QtWidgets.QTabBar.setUsesScrollButtons(useButtons)
Parameters

useButtons – bool

PySide6.QtWidgets.QTabBar.shape()
Return type

Shape

See also

setShape()

PySide6.QtWidgets.QTabBar.tabAt(pos)
Parameters

posPySide6.QtCore.QPoint

Return type

int

PySide6.QtWidgets.QTabBar.tabBarClicked(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.tabBarDoubleClicked(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.tabButton(index, position)
Parameters
Return type

PySide6.QtWidgets.QWidget

PySide6.QtWidgets.QTabBar.tabCloseRequested(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.tabData(index)
Parameters

index – int

Return type

object

PySide6.QtWidgets.QTabBar.tabIcon(index)
Parameters

index – int

Return type

PySide6.QtGui.QIcon

PySide6.QtWidgets.QTabBar.tabInserted(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.tabLayoutChange()
PySide6.QtWidgets.QTabBar.tabMoved(from, to)
Parameters
  • from – int

  • to – int

PySide6.QtWidgets.QTabBar.tabRect(index)
Parameters

index – int

Return type

PySide6.QtCore.QRect

PySide6.QtWidgets.QTabBar.tabRemoved(index)
Parameters

index – int

PySide6.QtWidgets.QTabBar.tabSizeHint(index)
Parameters

index – int

Return type

PySide6.QtCore.QSize

PySide6.QtWidgets.QTabBar.tabText(index)
Parameters

index – int

Return type

str

PySide6.QtWidgets.QTabBar.tabTextColor(index)
Parameters

index – int

Return type

PySide6.QtGui.QColor

PySide6.QtWidgets.QTabBar.tabToolTip(index)
Parameters

index – int

Return type

str

PySide6.QtWidgets.QTabBar.tabWhatsThis(index)
Parameters

index – int

Return type

str

PySide6.QtWidgets.QTabBar.tabsClosable()
Return type

bool

PySide6.QtWidgets.QTabBar.usesScrollButtons()
Return type

bool