QTabBar

Inheritance diagram of QTabBar

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

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

PySide.QtGui.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 PySide.QtGui.QTabWidget .

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

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

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

The PySide.QtGui.QTabBar.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 PySide.QtGui.QTabBar is RoundedNorth .

The most important part of PySide.QtGui.QTabBar ‘s API is the PySide.QtGui.QTabBar.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, PySide.QtGui.QTabBar.setCurrentIndex() , which can be used to select a tab programmatically. The function PySide.QtGui.QTabBar.currentIndex() returns the index of the current tab, PySide.QtGui.QTabBar.count() holds the number of tabs.

PySide.QtGui.QTabBar creates automatic mnemonic keys in the manner of PySide.QtGui.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 PySide.QtGui.QTabBar.tabRect() functions which returns the visual geometry of a single tab.

../../_images/plastique-tabbar.png A tab bar shown in the Plastique widget style.
../../_images/plastique-tabbar-truncated.png A truncated tab bar shown in the Plastique widget style.
class PySide.QtGui.QTabBar([parent=None])
Parameters:parentPySide.QtGui.QWidget

Creates a new tab bar with the given parent .

PySide.QtGui.QTabBar.SelectionBehavior

This enum type lists the behavior of PySide.QtGui.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.
PySide.QtGui.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.
PySide.QtGui.QTabBar.Shape

This enum type lists the built-in shapes supported by PySide.QtGui.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.
PySide.QtGui.QTabBar.addTab(text)
Parameters:text – unicode
Return type:PySide.QtCore.int

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

PySide.QtGui.QTabBar.addTab(icon, text)
Parameters:
Return type:

PySide.QtCore.int

This is an overloaded function.

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

PySide.QtGui.QTabBar.count()
Return type:PySide.QtCore.int

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

PySide.QtGui.QTabBar.currentChanged(index)
Parameters:indexPySide.QtCore.int
PySide.QtGui.QTabBar.currentIndex()
Return type:PySide.QtCore.int

This property holds the index of the tab bar’s visible tab.

The current index is -1 if there is no current tab.

PySide.QtGui.QTabBar.documentMode()
Return type:PySide.QtCore.bool

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.

PySide.QtGui.QTabBar.drawBase()
Return type:PySide.QtCore.bool

This property defines whether or not tab bar should draw its base..

If true then PySide.QtGui.QTabBar draws a base in relation to the styles overlab. Otherwise only the tabs are drawn.

See also

QStyle.pixelMetric() QStyle.PM_TabBarBaseOverlap PySide.QtGui.QStyleOptionTabBarBaseV2

PySide.QtGui.QTabBar.elideMode()
Return type:PySide.QtCore.Qt.TextElideMode

This property holds how to elide text in the tab bar.

This property 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.

PySide.QtGui.QTabBar.expanding()
Return type:PySide.QtCore.bool

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

By default the value is true.

PySide.QtGui.QTabBar.iconSize()
Return type:PySide.QtCore.QSize

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.

PySide.QtGui.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 PySide.QtGui.QStyleOptionTab , PySide.QtGui.QStyleOptionTabV2 , or PySide.QtGui.QStyleOptionTabV3 but don’t want to fill in all the information themselves. This function will check the version of the PySide.QtGui.QStyleOptionTab and fill in the additional values for a PySide.QtGui.QStyleOptionTabV2 and PySide.QtGui.QStyleOptionTabV3 .

PySide.QtGui.QTabBar.insertTab(index, text)
Parameters:
  • indexPySide.QtCore.int
  • text – unicode
Return type:

PySide.QtCore.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.

PySide.QtGui.QTabBar.insertTab(index, icon, text)
Parameters:
Return type:

PySide.QtCore.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 PySide.QtGui.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.

PySide.QtGui.QTabBar.isMovable()
Return type:PySide.QtCore.bool

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

By default, this property is false;

PySide.QtGui.QTabBar.isTabEnabled(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.bool

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

PySide.QtGui.QTabBar.moveTab(from, to)
Parameters:
  • fromPySide.QtCore.int
  • toPySide.QtCore.int

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

PySide.QtGui.QTabBar.removeTab(index)
Parameters:indexPySide.QtCore.int

Removes the tab at position index .

See also

QTabBar.SelectionBehavior

PySide.QtGui.QTabBar.selectionBehaviorOnRemove()
Return type:PySide.QtGui.QTabBar.SelectionBehavior

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 .

PySide.QtGui.QTabBar.setCurrentIndex(index)
Parameters:indexPySide.QtCore.int

This property holds the index of the tab bar’s visible tab.

The current index is -1 if there is no current tab.

PySide.QtGui.QTabBar.setDocumentMode(set)
Parameters:setPySide.QtCore.bool

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.

PySide.QtGui.QTabBar.setDrawBase(drawTheBase)
Parameters:drawTheBasePySide.QtCore.bool

This property defines whether or not tab bar should draw its base..

If true then PySide.QtGui.QTabBar draws a base in relation to the styles overlab. Otherwise only the tabs are drawn.

See also

QStyle.pixelMetric() QStyle.PM_TabBarBaseOverlap PySide.QtGui.QStyleOptionTabBarBaseV2

PySide.QtGui.QTabBar.setElideMode(arg__1)
Parameters:arg__1PySide.QtCore.Qt.TextElideMode

This property holds how to elide text in the tab bar.

This property 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.

PySide.QtGui.QTabBar.setExpanding(enabled)
Parameters:enabledPySide.QtCore.bool

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

By default the value is true.

PySide.QtGui.QTabBar.setIconSize(size)
Parameters:sizePySide.QtCore.QSize

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.

PySide.QtGui.QTabBar.setMovable(movable)
Parameters:movablePySide.QtCore.bool

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

By default, this property is false;

PySide.QtGui.QTabBar.setSelectionBehaviorOnRemove(behavior)
Parameters:behaviorPySide.QtGui.QTabBar.SelectionBehavior

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 .

PySide.QtGui.QTabBar.setShape(shape)
Parameters:shapePySide.QtGui.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.

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

PySide.QtGui.QTabBar.setTabData(index, data)
Parameters:
  • indexPySide.QtCore.int
  • data – object

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

PySide.QtGui.QTabBar.setTabEnabled(index, arg__2)
Parameters:
  • indexPySide.QtCore.int
  • arg__2PySide.QtCore.bool

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

PySide.QtGui.QTabBar.setTabIcon(index, icon)
Parameters:

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

PySide.QtGui.QTabBar.setTabText(index, text)
Parameters:
  • indexPySide.QtCore.int
  • text – unicode

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

PySide.QtGui.QTabBar.setTabTextColor(index, color)
Parameters:

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 PySide.QtGui.QTabBar foreground role instead.

PySide.QtGui.QTabBar.setTabToolTip(index, tip)
Parameters:
  • indexPySide.QtCore.int
  • tip – unicode

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

PySide.QtGui.QTabBar.setTabWhatsThis(index, text)
Parameters:
  • indexPySide.QtCore.int
  • text – unicode

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

PySide.QtGui.QTabBar.setTabsClosable(closable)
Parameters:closablePySide.QtCore.bool

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

When PySide.QtGui.QTabBar.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.

PySide.QtGui.QTabBar.setUsesScrollButtons(useButtons)
Parameters:useButtonsPySide.QtCore.bool

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

See also

PySide.QtGui.QTabBar.elideMode() QTabWidget.usesScrollButtons QStyle.SH_TabBar_PreferNoArrows

PySide.QtGui.QTabBar.shape()
Return type:PySide.QtGui.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.

PySide.QtGui.QTabBar.tabAt(pos)
Parameters:posPySide.QtCore.QPoint
Return type:PySide.QtCore.int

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

PySide.QtGui.QTabBar.tabButton(index, position)
Parameters:
Return type:

PySide.QtGui.QWidget

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

PySide.QtGui.QTabBar.tabCloseRequested(index)
Parameters:indexPySide.QtCore.int
PySide.QtGui.QTabBar.tabData(index)
Parameters:indexPySide.QtCore.int
Return type:object

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

PySide.QtGui.QTabBar.tabIcon(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QIcon

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

PySide.QtGui.QTabBar.tabInserted(index)
Parameters:indexPySide.QtCore.int

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

PySide.QtGui.QTabBar.tabLayoutChange()

This virtual handler is called whenever the tab layout changes.

PySide.QtGui.QTabBar.tabMoved(from, to)
Parameters:
  • fromPySide.QtCore.int
  • toPySide.QtCore.int
PySide.QtGui.QTabBar.tabRect(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QRect

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

PySide.QtGui.QTabBar.tabRemoved(index)
Parameters:indexPySide.QtCore.int

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

PySide.QtGui.QTabBar.tabSizeHint(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.QSize

Returns the size hint for the tab at position index .

PySide.QtGui.QTabBar.tabText(index)
Parameters:indexPySide.QtCore.int
Return type:unicode

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

PySide.QtGui.QTabBar.tabTextColor(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QColor

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

PySide.QtGui.QTabBar.tabToolTip(index)
Parameters:indexPySide.QtCore.int
Return type:unicode

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

PySide.QtGui.QTabBar.tabWhatsThis(index)
Parameters:indexPySide.QtCore.int
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.

PySide.QtGui.QTabBar.tabsClosable()
Return type:PySide.QtCore.bool

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

When PySide.QtGui.QTabBar.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.

PySide.QtGui.QTabBar.usesScrollButtons()
Return type:PySide.QtCore.bool

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

See also

PySide.QtGui.QTabBar.elideMode() QTabWidget.usesScrollButtons QStyle.SH_TabBar_PreferNoArrows