QTabBar

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

Inheritance diagram of PySide2.QtWidgets.QTabBar

Synopsis

Functions

Virtual functions

Slots

Signals

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 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:

For subclasses, you might also need the tabRect() 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 QTabBar([parent=None])
param parent

QWidget

Creates a new tab bar with the given parent .

PySide2.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.

PySide2.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.

PySide2.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.

PySide2.QtWidgets.QTabBar.accessibleTabName(index)
Parameters

indexint

Return type

unicode

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

PySide2.QtWidgets.QTabBar.addTab(icon, text)
Parameters
  • iconQIcon

  • text – unicode

Return type

int

This is an overloaded function.

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

PySide2.QtWidgets.QTabBar.addTab(text)
Parameters

text – unicode

Return type

int

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

PySide2.QtWidgets.QTabBar.autoHide()
Return type

bool

See also

setAutoHide()

PySide2.QtWidgets.QTabBar.changeCurrentOnDrag()
Return type

bool

PySide2.QtWidgets.QTabBar.count()
Return type

int

PySide2.QtWidgets.QTabBar.currentChanged(index)
Parameters

indexint

PySide2.QtWidgets.QTabBar.currentIndex()
Return type

int

PySide2.QtWidgets.QTabBar.documentMode()
Return type

bool

PySide2.QtWidgets.QTabBar.drawBase()
Return type

bool

See also

setDrawBase()

PySide2.QtWidgets.QTabBar.elideMode()
Return type

TextElideMode

See also

setElideMode()

PySide2.QtWidgets.QTabBar.expanding()
Return type

bool

See also

setExpanding()

PySide2.QtWidgets.QTabBar.iconSize()
Return type

QSize

See also

setIconSize()

PySide2.QtWidgets.QTabBar.initStyleOption(option, tabIndex)
Parameters

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

PySide2.QtWidgets.QTabBar.insertTab(index, icon, text)
Parameters
  • indexint

  • iconQIcon

  • text – unicode

Return type

int

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.

PySide2.QtWidgets.QTabBar.insertTab(index, text)
Parameters
  • indexint

  • text – unicode

Return type

int

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.

PySide2.QtWidgets.QTabBar.isMovable()
Return type

bool

PySide2.QtWidgets.QTabBar.isTabEnabled(index)
Parameters

indexint

Return type

bool

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

PySide2.QtWidgets.QTabBar.minimumTabSizeHint(index)
Parameters

indexint

Return type

QSize

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

PySide2.QtWidgets.QTabBar.moveTab(from, to)
Parameters
  • fromint

  • toint

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

PySide2.QtWidgets.QTabBar.removeTab(index)
Parameters

indexint

Removes the tab at position index .

See also

SelectionBehavior

PySide2.QtWidgets.QTabBar.selectionBehaviorOnRemove()
Return type

SelectionBehavior

PySide2.QtWidgets.QTabBar.setAccessibleTabName(index, name)
Parameters
  • indexint

  • name – unicode

Sets the accessibleName of the tab at position index to name .

PySide2.QtWidgets.QTabBar.setAutoHide(hide)
Parameters

hidebool

See also

autoHide()

PySide2.QtWidgets.QTabBar.setChangeCurrentOnDrag(change)
Parameters

changebool

PySide2.QtWidgets.QTabBar.setCurrentIndex(index)
Parameters

indexint

See also

currentIndex()

PySide2.QtWidgets.QTabBar.setDocumentMode(set)
Parameters

setbool

See also

documentMode()

PySide2.QtWidgets.QTabBar.setDrawBase(drawTheBase)
Parameters

drawTheBasebool

See also

drawBase()

PySide2.QtWidgets.QTabBar.setElideMode(arg__1)
Parameters

arg__1TextElideMode

See also

elideMode()

PySide2.QtWidgets.QTabBar.setExpanding(enabled)
Parameters

enabledbool

See also

expanding()

PySide2.QtWidgets.QTabBar.setIconSize(size)
Parameters

sizeQSize

See also

iconSize()

PySide2.QtWidgets.QTabBar.setMovable(movable)
Parameters

movablebool

See also

isMovable()

PySide2.QtWidgets.QTabBar.setSelectionBehaviorOnRemove(behavior)
Parameters

behaviorSelectionBehavior

PySide2.QtWidgets.QTabBar.setShape(shape)
Parameters

shapeShape

See also

shape()

PySide2.QtWidgets.QTabBar.setTabButton(index, position, widget)
Parameters

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

PySide2.QtWidgets.QTabBar.setTabData(index, data)
Parameters
  • indexint

  • data – object

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

See also

tabData()

PySide2.QtWidgets.QTabBar.setTabEnabled(index, arg__2)
Parameters
  • indexint

  • arg__2bool

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

See also

isTabEnabled()

PySide2.QtWidgets.QTabBar.setTabIcon(index, icon)
Parameters
  • indexint

  • iconQIcon

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

See also

tabIcon()

PySide2.QtWidgets.QTabBar.setTabText(index, text)
Parameters
  • indexint

  • text – unicode

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

See also

tabText()

PySide2.QtWidgets.QTabBar.setTabTextColor(index, color)
Parameters
  • indexint

  • colorQColor

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

PySide2.QtWidgets.QTabBar.setTabToolTip(index, tip)
Parameters
  • indexint

  • tip – unicode

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

See also

tabToolTip()

PySide2.QtWidgets.QTabBar.setTabWhatsThis(index, text)
Parameters
  • indexint

  • text – unicode

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

See also

tabWhatsThis()

PySide2.QtWidgets.QTabBar.setTabsClosable(closable)
Parameters

closablebool

See also

tabsClosable()

PySide2.QtWidgets.QTabBar.setUsesScrollButtons(useButtons)
Parameters

useButtonsbool

PySide2.QtWidgets.QTabBar.shape()
Return type

Shape

See also

setShape()

PySide2.QtWidgets.QTabBar.tabAt(pos)
Parameters

posQPoint

Return type

int

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

PySide2.QtWidgets.QTabBar.tabBarClicked(index)
Parameters

indexint

PySide2.QtWidgets.QTabBar.tabBarDoubleClicked(index)
Parameters

indexint

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

QWidget

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

See also

setTabButton()

PySide2.QtWidgets.QTabBar.tabCloseRequested(index)
Parameters

indexint

PySide2.QtWidgets.QTabBar.tabData(index)
Parameters

indexint

Return type

object

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

See also

setTabData()

PySide2.QtWidgets.QTabBar.tabIcon(index)
Parameters

indexint

Return type

QIcon

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

See also

setTabIcon()

PySide2.QtWidgets.QTabBar.tabInserted(index)
Parameters

indexint

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

See also

tabRemoved()

PySide2.QtWidgets.QTabBar.tabLayoutChange()

This virtual handler is called whenever the tab layout changes.

See also

tabRect()

PySide2.QtWidgets.QTabBar.tabMoved(from, to)
Parameters
  • fromint

  • toint

PySide2.QtWidgets.QTabBar.tabRect(index)
Parameters

indexint

Return type

QRect

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

PySide2.QtWidgets.QTabBar.tabRemoved(index)
Parameters

indexint

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

See also

tabInserted()

PySide2.QtWidgets.QTabBar.tabSizeHint(index)
Parameters

indexint

Return type

QSize

Returns the size hint for the tab at position index .

PySide2.QtWidgets.QTabBar.tabText(index)
Parameters

indexint

Return type

unicode

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

See also

setTabText()

PySide2.QtWidgets.QTabBar.tabTextColor(index)
Parameters

indexint

Return type

QColor

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

PySide2.QtWidgets.QTabBar.tabToolTip(index)
Parameters

indexint

Return type

unicode

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

See also

setTabToolTip()

PySide2.QtWidgets.QTabBar.tabWhatsThis(index)
Parameters

indexint

Return type

unicode

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

PySide2.QtWidgets.QTabBar.tabsClosable()
Return type

bool

PySide2.QtWidgets.QTabBar.usesScrollButtons()
Return type

bool