QTabWidget

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

The PySide.QtGui.QTabWidget class provides a stack of tabbed widgets.

A tab widget provides a tab bar (see PySide.QtGui.QTabBar ) and a “page area” that is used to display pages related to each tab. By default, the tab bar is shown above the page area, but different configurations are available (see QTabWidget.TabPosition ). Each tab is associated with a different widget (called a page). Only the current page is shown in the page area; all the other pages are hidden. The user can show a different page by clicking on its tab or by pressing its Alt+*letter* shortcut if it has one.

The normal way to use PySide.QtGui.QTabWidget is to do the following:

The position of the tabs is defined by PySide.QtGui.QTabWidget.tabPosition() , their shape by PySide.QtGui.QTabWidget.tabShape() .

The signal PySide.QtGui.QTabWidget.currentChanged() is emitted when the user selects a page.

The current page index is available as PySide.QtGui.QTabWidget.currentIndex() , the current page widget with PySide.QtGui.QTabWidget.currentWidget() . You can retrieve a pointer to a page widget with a given index using PySide.QtGui.QTabWidget.widget() , and can find the index position of a widget with PySide.QtGui.QTabWidget.indexOf() . Use PySide.QtGui.QTabWidget.setCurrentWidget() or PySide.QtGui.QTabWidget.setCurrentIndex() to show a particular page.

You can change a tab’s text and icon using PySide.QtGui.QTabWidget.setTabText() or PySide.QtGui.QTabWidget.setTabIcon() . A tab and its associated page can be removed with PySide.QtGui.QTabWidget.removeTab() .

Each tab is either enabled or disabled at any given time (see PySide.QtGui.QTabWidget.setTabEnabled() ). If a tab is enabled, the tab text is drawn normally and the user can select that tab. If it is disabled, the tab is drawn in a different way and the user cannot select that tab. Note that even if a tab is disabled, the page can still be visible, for example if all of the tabs happen to be disabled.

Tab widgets can be a very good way to split up a complex dialog. An alternative is to use a PySide.QtGui.QStackedWidget for which you provide some means of navigating between pages, for example, a PySide.QtGui.QToolBar or a PySide.QtGui.QListWidget .

Most of the functionality in PySide.QtGui.QTabWidget is provided by a PySide.QtGui.QTabBar (at the top, providing the tabs) and a PySide.QtGui.QStackedWidget (most of the area, organizing the individual pages).

../../_images/windowsxp-tabwidget.png ../../_images/macintosh-tabwidget.png ../../_images/plastique-tabwidget.png
A Windows XP style tab widget. A Macintosh style tab widget. A Plastique style tab widget.
class PySide.QtGui.QTabWidget([parent=None])
Parameters:parentPySide.QtGui.QWidget

Constructs a tabbed widget with parent parent .

PySide.QtGui.QTabWidget.TabShape

This enum type defines the shape of the tabs:

Constant Description
QTabWidget.Rounded The tabs are drawn with a rounded look. This is the default shape.
QTabWidget.Triangular The tabs are drawn with a triangular look.
PySide.QtGui.QTabWidget.TabPosition

This enum type defines where PySide.QtGui.QTabWidget draws the tab row:

Constant Description
QTabWidget.North The tabs are drawn above the pages.
QTabWidget.South The tabs are drawn below the pages.
QTabWidget.West The tabs are drawn to the left of the pages.
QTabWidget.East The tabs are drawn to the right of the pages.
PySide.QtGui.QTabWidget.addTab(widget, arg__2)
Parameters:
Return type:

PySide.QtCore.int

Adds a tab with the given page and label to the tab widget, and returns the index of the tab in the tab bar.

If the tab’s label contains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is “Bro&wse” then Alt+W becomes a shortcut which will move the focus to this tab.

Note

If you call PySide.QtGui.QTabWidget.addTab() after PySide.QtGui.QWidget.show() , the layout system will try to adjust to the changes in its widgets hierarchy and may cause flicker. To prevent this, you can set the QWidget.updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

PySide.QtGui.QTabWidget.addTab(widget, icon, label)
Parameters:
Return type:

PySide.QtCore.int

This is an overloaded function.

Adds a tab with the given page , icon , and label to the tab widget, and returns the index of the tab in the tab bar.

This function is the same as PySide.QtGui.QTabWidget.addTab() , but with an additional icon .

PySide.QtGui.QTabWidget.clear()

Removes all the pages, but does not delete them. Calling this function is equivalent to calling PySide.QtGui.QTabWidget.removeTab() until the tab widget is empty.

PySide.QtGui.QTabWidget.cornerWidget([corner=Qt.TopRightCorner])
Parameters:cornerPySide.QtCore.Qt.Corner
Return type:PySide.QtGui.QWidget
PySide.QtGui.QTabWidget.count()
Return type:PySide.QtCore.int

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

By default, this property contains a value of 0.

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

This property holds the index position of the current tab page.

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

By default, this property contains a value of -1 because there are initially no tabs in the widget.

PySide.QtGui.QTabWidget.currentWidget()
Return type:PySide.QtGui.QWidget

Returns a pointer to the page currently being displayed by the tab dialog. The tab dialog does its best to make sure that this value is never 0 (but if you try hard enough, it can be).

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

This property holds Whether or not the tab widget is rendered in a mode suitable for document pages. This is the same as document mode on Mac OS X..

When this property is set the tab widget frame is not rendered. This mode is useful for showing document-type pages where the page covers most of the tab widget area.

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

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

This property holds The size for icons in the tab bar.

The default value is style-dependent. This is the maximum size that the icons will have. Icons are not scaled up if they are of smaller size.

See also

QTabBar.iconSize

PySide.QtGui.QTabWidget.indexOf(widget)
Parameters:widgetPySide.QtGui.QWidget
Return type:PySide.QtCore.int

Returns the index position of the page occupied by the widget w , or -1 if the widget cannot be found.

PySide.QtGui.QTabWidget.initStyleOption(option)
Parameters:optionPySide.QtGui.QStyleOptionTabWidgetFrame

Initialize option with the values from this PySide.QtGui.QTabWidget . This method is useful for subclasses when they need a PySide.QtGui.QStyleOptionTabWidgetFrame , but don’t want to fill in all the information themselves.

PySide.QtGui.QTabWidget.insertTab(index, widget, arg__3)
Parameters:
Return type:

PySide.QtCore.int

Inserts a tab with the given label and page into the tab widget at the specified index , and returns the index of the inserted tab in the tab bar.

The label is displayed in the tab and may vary in appearance depending on the configuration of the tab widget.

If the tab’s label contains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is “Bro&wse” then Alt+W becomes a shortcut which will move the focus to this tab.

If index is out of range, the tab is simply appended. Otherwise it is inserted at the specified position.

If the PySide.QtGui.QTabWidget was empty before this function is called, the new page becomes the current page. Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current page.

Note

If you call PySide.QtGui.QTabWidget.insertTab() after PySide.QtGui.QWidget.show() , the layout system will try to adjust to the changes in its widgets hierarchy and may cause flicker. To prevent this, you can set the QWidget.updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

PySide.QtGui.QTabWidget.insertTab(index, widget, icon, label)
Parameters:
Return type:

PySide.QtCore.int

This is an overloaded function.

Inserts a tab with the given label , page , and icon into the tab widget at the specified index , and returns the index of the inserted tab in the tab bar.

This function is the same as PySide.QtGui.QTabWidget.insertTab() , but with an additional icon .

PySide.QtGui.QTabWidget.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.QTabWidget.isTabEnabled(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtCore.bool

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

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

Removes the tab at position index from this stack of widgets. The page widget itself is not deleted.

PySide.QtGui.QTabWidget.setCornerWidget(w[, corner=Qt.TopRightCorner])
Parameters:
PySide.QtGui.QTabWidget.setCurrentIndex(index)
Parameters:indexPySide.QtCore.int

This property holds the index position of the current tab page.

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

By default, this property contains a value of -1 because there are initially no tabs in the widget.

PySide.QtGui.QTabWidget.setCurrentWidget(widget)
Parameters:widgetPySide.QtGui.QWidget

Makes widget the current widget. The widget used must be a page in this tab widget.

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

This property holds Whether or not the tab widget is rendered in a mode suitable for document pages. This is the same as document mode on Mac OS X..

When this property is set the tab widget frame is not rendered. This mode is useful for showing document-type pages where the page covers most of the tab widget area.

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

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

This property holds The size for icons in the tab bar.

The default value is style-dependent. This is the maximum size that the icons will have. Icons are not scaled up if they are of smaller size.

See also

QTabBar.iconSize

PySide.QtGui.QTabWidget.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.QTabWidget.setTabBar(arg__1)
Parameters:arg__1PySide.QtGui.QTabBar

Replaces the dialog’s PySide.QtGui.QTabBar heading with the tab bar tb . Note that this must be called before any tabs have been added, or the behavior is undefined.

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

If enable is true, the page at position index is enabled; otherwise the page at position index is disabled. The page’s tab is redrawn appropriately.

PySide.QtGui.QTabWidget uses QWidget.setEnabled() internally, rather than keeping a separate flag.

Note that even a disabled tab/page may be visible. If the page is visible already, PySide.QtGui.QTabWidget will not hide it; if all the pages are disabled, PySide.QtGui.QTabWidget will show one of them.

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

This is an overloaded function.

Sets the icon for the tab at position index .

PySide.QtGui.QTabWidget.setTabPosition(arg__1)
Parameters:arg__1PySide.QtGui.QTabWidget.TabPosition

This property holds the position of the tabs in this tab widget.

Possible values for this property are described by the QTabWidget.TabPosition enum.

By default, this property is set to North .

See also

QTabWidget.TabPosition

PySide.QtGui.QTabWidget.setTabShape(s)
Parameters:sPySide.QtGui.QTabWidget.TabShape

This property holds the shape of the tabs in this tab widget.

Possible values for this property are QTabWidget.Rounded (default) or QTabWidget.Triangular .

See also

QTabWidget.TabShape

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

Defines a new label for the page at position index ‘s tab.

If the provided text contains an ampersand character (‘&’), a shortcut is automatically created for it. The character that follows the ‘&’ will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See the QShortcut documentation for details (to display an actual ampersand, use ‘&&’).

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

Sets the tab tool tip for the page at position index to tip .

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

Sets the What’s This help text for the page at position index to text .

PySide.QtGui.QTabWidget.setTabsClosable(closeable)
Parameters:closeablePySide.QtCore.bool

This property holds whether close buttons are automatically added to each tab..

PySide.QtGui.QTabWidget.setUpLayout([arg__1=false])
Parameters:arg__1PySide.QtCore.bool
PySide.QtGui.QTabWidget.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.QTabWidget.elideMode() QTabBar.usesScrollButtons QStyle.SH_TabBar_PreferNoArrows

PySide.QtGui.QTabWidget.tabBar()
Return type:PySide.QtGui.QTabBar

Returns the current PySide.QtGui.QTabBar .

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

Returns the icon for the tab on the page at position index .

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

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

PySide.QtGui.QTabWidget.tabPosition()
Return type:PySide.QtGui.QTabWidget.TabPosition

This property holds the position of the tabs in this tab widget.

Possible values for this property are described by the QTabWidget.TabPosition enum.

By default, this property is set to North .

See also

QTabWidget.TabPosition

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

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

PySide.QtGui.QTabWidget.tabShape()
Return type:PySide.QtGui.QTabWidget.TabShape

This property holds the shape of the tabs in this tab widget.

Possible values for this property are QTabWidget.Rounded (default) or QTabWidget.Triangular .

See also

QTabWidget.TabShape

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

Returns the label text for the tab on the page at position index .

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

Returns the tab tool tip for the page at position index or an empty string if no tool tip has been set.

PySide.QtGui.QTabWidget.tabWhatsThis(index)
Parameters:indexPySide.QtCore.int
Return type:unicode

Returns the What’s This help text for the page at position index , or an empty string if no help text has been set.

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

This property holds whether close buttons are automatically added to each tab..

PySide.QtGui.QTabWidget.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.QTabWidget.elideMode() QTabBar.usesScrollButtons QStyle.SH_TabBar_PreferNoArrows

PySide.QtGui.QTabWidget.widget(index)
Parameters:indexPySide.QtCore.int
Return type:PySide.QtGui.QWidget

Returns the tab page at index position index or 0 if the index is out of range.