PySide6.QtWidgets.QTabWidget¶
- class QTabWidget¶
- The - QTabWidgetclass provides a stack of tabbed widgets. More…- Synopsis¶- Properties¶- countᅟ- The number of tabs in the tab bar
- currentIndexᅟ- The index position of the current tab page
- documentModeᅟ- Whether or not the tab widget is rendered in a mode suitable for document pages. This is the same as document mode on macOS
- elideModeᅟ- How to elide text in the tab bar
- iconSizeᅟ- Size for icons in the tab bar
- movableᅟ- This property holds whether the user can move the tabs within the tabbar area
- tabBarAutoHideᅟ- If true, the tab bar is automatically hidden when it contains less than 2 tabs
- tabPositionᅟ- The position of the tabs in this tab widget
- tabShapeᅟ- The shape of the tabs in this tab widget
- tabsClosableᅟ- Whether close buttons are automatically added to each tab
- usesScrollButtonsᅟ- Whether or not a tab bar should use buttons to scroll tabs when it has many tabs
 - Methods¶- def - __init__()
- def - addTab()
- def - clear()
- def - cornerWidget()
- def - count()
- def - currentIndex()
- def - currentWidget()
- def - documentMode()
- def - elideMode()
- def - iconSize()
- def - indexOf()
- def - insertTab()
- def - isMovable()
- def - isTabEnabled()
- def - isTabVisible()
- def - removeTab()
- def - setElideMode()
- def - setIconSize()
- def - setMovable()
- def - setTabBar()
- def - setTabEnabled()
- def - setTabIcon()
- def - setTabPosition()
- def - setTabShape()
- def - setTabText()
- def - setTabToolTip()
- def - setTabVisible()
- def - tabBar()
- def - tabBarAutoHide()
- def - tabIcon()
- def - tabPosition()
- def - tabShape()
- def - tabText()
- def - tabToolTip()
- def - tabWhatsThis()
- def - tabsClosable()
- def - widget()
 - Virtual methods¶
- def - tabInserted()
- def - tabRemoved()
 - Slots¶- Signals¶- def - currentChanged()
- def - tabBarClicked()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶  - A tab widget provides a tab bar (see - 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- 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 - QTabWidgetis to do the following:- Create a - QTabWidget.
- Create a - QWidgetfor each of the pages in the tab dialog, but do not specify parent widgets for them.
- Insert child widgets into the page widget, using layouts to position them as normal. 
- Call - addTab()or- insertTab()to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.
 - The position of the tabs is defined by - tabPosition, their shape by- tabShape.- The signal - currentChanged()is emitted when the user selects a page.- The current page index is available as - currentIndex(), the current page widget with- currentWidget(). You can retrieve a pointer to a page widget with a given index using- widget(), and can find the index position of a widget with- indexOf(). Use- setCurrentWidget()or- setCurrentIndex()to show a particular page.- You can change a tab’s text and icon using - setTabText()or- setTabIcon(). A tab and its associated page can be removed with- removeTab().- Each tab is either enabled or disabled at any given time (see - 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 - QStackedWidgetfor which you provide some means of navigating between pages, for example, a- QToolBaror a- QListWidget.- Most of the functionality in - QTabWidgetis provided by a- QTabBar(at the top, providing the tabs) and a- QStackedWidget(most of the area, organizing the individual pages).- See also - QTabBar- QStackedWidget- QToolBoxTab Dialog Example- class TabPosition¶
- This enum type defines where - QTabWidgetdraws 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. 
 - class 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. 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property countᅟ: int¶
 - This property holds the number of tabs in the tab bar. - By default, this property contains a value of 0. - Access functions:
 - property currentIndexᅟ: 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. - Access functions:
 - property documentModeᅟ: 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 macOS.. - 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. - Access functions:
 - property elideModeᅟ: 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. - Access functions:
 - 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 - Access functions:
 - property movableᅟ: bool¶
 - This property holds This property holds whether the user can move the tabs within the tabbar area.. - By default, this property is - false;- Access functions:
 - property tabBarAutoHideᅟ: bool¶
 - This property holds If true, the tab bar is automatically hidden when it contains less than 2 tabs.. - By default, this property is false. - See also - visible- Access functions:
 - property tabPositionᅟ: QTabWidget.TabPosition¶
 - This property holds the position of the tabs in this tab widget. - Possible values for this property are described by the - TabPositionenum.- By default, this property is set to - North.- See also - Access functions:
 - property tabShapeᅟ: QTabWidget.TabShape¶
 - This property holds the shape of the tabs in this tab widget. - Possible values for this property are - Rounded(default) or- Triangular.- See also - Access functions:
 - property tabsClosableᅟ: bool¶
 - This property holds whether close buttons are automatically added to each tab.. - See also - Access functions:
 - property usesScrollButtonsᅟ: 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 dependent. - Access functions:
 - Constructs a tabbed widget with parent - parent.- Adds a tab with the given - pageand- labelto the tab widget, and returns the index of the tab in the tab bar. Ownership of- pageis passed on to the- QTabWidget.- If the tab’s - labelcontains 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 addTab() after - 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- updatesEnabledproperty to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.- See also - This is an overloaded function. - Adds a tab with the given - page,- icon, and- labelto the tab widget, and returns the index of the tab in the tab bar. Ownership of- pageis passed on to the- QTabWidget.- This function is the same as - addTab(), but with an additional- icon.- clear()¶
 - Removes all the pages, but does not delete them. Calling this function is equivalent to calling - removeTab()until the tab widget is empty.- Returns the widget shown in the - cornerof the tab widget or- None.- See also - count()¶
- Return type:
- int 
 
 - Getter of property - countᅟ.- currentChanged(index)¶
- Parameters:
- index – int 
 
 - This signal is emitted whenever the current page index changes. The parameter is the new current page - indexposition, or -1 if there isn’t a new one (for example, if there are no widgets in the- QTabWidget)- See also - Notification signal of property - currentIndexᅟ.- currentIndex()¶
- Return type:
- int 
 - See also 
 - Getter of property - currentIndexᅟ.- 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). - See also - documentMode()¶
- Return type:
- bool 
 - See also 
 - Getter of property - documentModeᅟ.- elideMode()¶
- Return type:
 - See also 
 - Getter of property - elideModeᅟ.- iconSize()¶
- Return type:
 - See also 
 - Getter of property - iconSizeᅟ.- Returns the index position of the page occupied by the widget - w, or -1 if the widget cannot be found.- initStyleOption(option)¶
- Parameters:
- option – - QStyleOptionTabWidgetFrame
 
 - Initialize - optionwith the values from this- QTabWidget. This method is useful for subclasses when they need a- QStyleOptionTabWidgetFrame, but don’t want to fill in all the information themselves.- See also - insertTab(index, widget, label)¶
- Parameters:
- index – int 
- widget – - QWidget
- label – str 
 
- Return type:
- int 
 
 - Inserts a tab with the given - labeland- pageinto the tab widget at the specified- index, and returns the index of the inserted tab in the tab bar. Ownership of- pageis passed on to the- QTabWidget.- The label is displayed in the tab and may vary in appearance depending on the configuration of the tab widget. - If the tab’s - labelcontains 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 - indexis out of range, the tab is simply appended. Otherwise it is inserted at the specified position.- If the - QTabWidgetwas 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 insertTab() after - 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- updatesEnabledproperty to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.- See also - insertTab(index, widget, icon, label)
 - This is an overloaded function. - Inserts a tab with the given - label,- page, and- iconinto the tab widget at the specified- index, and returns the index of the inserted tab in the tab bar. Ownership of- pageis passed on to the- QTabWidget.- This function is the same as - insertTab(), but with an additional- icon.- isMovable()¶
- Return type:
- bool 
 
 - Getter of property - movableᅟ.- isTabEnabled(index)¶
- Parameters:
- index – int 
- Return type:
- bool 
 
 - Returns - trueif the page at position- indexis enabled; otherwise returns- false.- See also - isTabVisible(index)¶
- Parameters:
- index – int 
- Return type:
- bool 
 
 - Returns true if the page at position - indexis visible; otherwise returns false.- See also - removeTab(index)¶
- Parameters:
- index – int 
 
 - Removes the tab at position - indexfrom this stack of widgets. The page widget itself is not deleted.- See also - Sets the given - widgetto be shown in the specified- cornerof the tab widget. The geometry of the widget is determined based on the widget’s- sizeHint()and the- style().- Only the horizontal element of the - cornerwill be used.- Passing - Noneshows no widget in the corner.- Any previously set corner widget is hidden. - All widgets set here will be deleted by the tab widget when it is destroyed unless you separately reparent the widget after setting some other corner widget (or - None).- Note: Corner widgets are designed for - Northand- Southtab positions; other orientations are known to not work properly.- See also - setCurrentIndex(index)¶
- Parameters:
- index – int 
 - See also 
 - Setter of property - currentIndexᅟ.- Makes - widgetthe current widget. The- widgetused must be a page in this tab widget.- See also - setDocumentMode(set)¶
- Parameters:
- set – bool 
 - See also 
 - Setter of property - documentModeᅟ.- setElideMode(mode)¶
- Parameters:
- mode – - TextElideMode
 - See also 
 - Setter of property - elideModeᅟ.- Setter of property - iconSizeᅟ.- setMovable(movable)¶
- Parameters:
- movable – bool 
 - See also 
 - Setter of property - movableᅟ.- Replaces the dialog’s - QTabBarheading with the tab bar- tb. Note that this must be called before any tabs have been added, or the behavior is undefined.- See also - setTabBarAutoHide(enabled)¶
- Parameters:
- enabled – bool 
 - See also 
 - Setter of property - tabBarAutoHideᅟ.- setTabEnabled(index, enabled)¶
- Parameters:
- index – int 
- enabled – bool 
 
 
 - If - enableis true, the page at position- indexis enabled; otherwise the page at position- indexis disabled. The page’s tab is redrawn appropriately.- QTabWidgetuses- setEnabled()internally, rather than keeping a separate flag.- Note that even a disabled tab/page may be visible. If the page is visible already, - QTabWidgetwill not hide it; if all the pages are disabled,- QTabWidgetwill show one of them.- See also - Sets the - iconfor the tab at position- index.- See also - setTabPosition(position)¶
- Parameters:
- position – - TabPosition
 - See also 
 - Setter of property - tabPositionᅟ.- Setter of property - tabShapeᅟ.- setTabText(index, text)¶
- Parameters:
- index – int 
- text – str 
 
 
 - Defines a new - labelfor 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 ‘&&’). - See also - setTabToolTip(index, tip)¶
- Parameters:
- index – int 
- tip – str 
 
 
 - Sets the tab tool tip for the page at position - indexto- tip.- See also - setTabVisible(index, visible)¶
- Parameters:
- index – int 
- visible – bool 
 
 
 - If - visibleis true, the page at position- indexis visible; otherwise the page at position- indexis hidden. The page’s tab is redrawn appropriately.- See also - setTabWhatsThis(index, text)¶
- Parameters:
- index – int 
- text – str 
 
 
 - Sets the What’s This help text for the page at position - indexto- text.- See also - setTabsClosable(closeable)¶
- Parameters:
- closeable – bool 
 - See also 
 - Setter of property - tabsClosableᅟ.- setUsesScrollButtons(useButtons)¶
- Parameters:
- useButtons – bool 
 - See also 
 - Setter of property - usesScrollButtonsᅟ.- Returns the current - QTabBar.- See also - tabBarAutoHide()¶
- Return type:
- bool 
 - See also 
 - Getter of property - tabBarAutoHideᅟ.- tabBarClicked(index)¶
- Parameters:
- index – int 
 
 - This signal is emitted when user clicks on a tab at an - index.- indexrefers to the tab clicked, or -1 if no tab is under the cursor.- tabBarDoubleClicked(index)¶
- Parameters:
- index – int 
 
 - This signal is emitted when the user double clicks on a tab at an - index.- indexis the index of a clicked tab, or -1 if no tab is under the cursor.- tabCloseRequested(index)¶
- Parameters:
- index – int 
 
 - This signal is emitted when the close button on a tab is clicked. The - indexis the index that should be removed.- See also - Returns the icon for the tab on the page at position - index.- See also - tabInserted(index)¶
- Parameters:
- index – int 
 
 - This virtual handler is called after a new tab was added or inserted at position - index.- See also - tabPosition()¶
- Return type:
 - See also 
 - Getter of property - tabPositionᅟ.- tabRemoved(index)¶
- Parameters:
- index – int 
 
 - This virtual handler is called after a tab was removed from position - index.- See also - tabShape()¶
- Return type:
 - See also 
 - Getter of property - tabShapeᅟ.- tabText(index)¶
- Parameters:
- index – int 
- Return type:
- str 
 
 - Returns the label text for the tab on the page at position - index.- See also - tabToolTip(index)¶
- Parameters:
- index – int 
- Return type:
- str 
 
 - Returns the tab tool tip for the page at position - indexor an empty string if no tool tip has been set.- See also - tabWhatsThis(index)¶
- Parameters:
- index – int 
- Return type:
- str 
 
 - Returns the What’s This help text for the page at position - index, or an empty string if no help text has been set.- See also - tabsClosable()¶
- Return type:
- bool 
 - See also 
 - Getter of property - tabsClosableᅟ.- usesScrollButtons()¶
- Return type:
- bool 
 - See also 
 - Getter of property - usesScrollButtonsᅟ.- Returns the tab page at index position - indexor- Noneif the- indexis out of range.