QTabWidget露
The
QTabWidgetclass provides a stack of tabbed widgets. More鈥

Synopsis露
Functions露
def
addTab(widget, arg__2)def
addTab(widget, icon, label)def
clear()def
cornerWidget([corner=Qt.TopRightCorner])def
count()def
currentIndex()def
currentWidget()def
documentMode()def
elideMode()def
iconSize()def
indexOf(widget)def
initStyleOption(option)def
insertTab(index, widget, arg__3)def
insertTab(index, widget, icon, label)def
isMovable()def
isTabEnabled(index)def
isTabVisible(index)def
removeTab(index)def
setCornerWidget(w[, corner=Qt.TopRightCorner])def
setDocumentMode(set)def
setElideMode(mode)def
setIconSize(size)def
setMovable(movable)def
setTabBar(arg__1)def
setTabBarAutoHide(enabled)def
setTabEnabled(index, enabled)def
setTabIcon(index, icon)def
setTabPosition(position)def
setTabShape(s)def
setTabText(index, text)def
setTabToolTip(index, tip)def
setTabVisible(index, visible)def
setTabWhatsThis(index, text)def
setTabsClosable(closeable)def
setUsesScrollButtons(useButtons)def
tabBar()def
tabBarAutoHide()def
tabIcon(index)def
tabPosition()def
tabShape()def
tabText(index)def
tabToolTip(index)def
tabWhatsThis(index)def
tabsClosable()def
usesScrollButtons()def
widget(index)
Virtual functions露
def
tabInserted(index)def
tabRemoved(index)
Slots露
def
setCurrentIndex(index)def
setCurrentWidget(widget)
Signals露
def
currentChanged(index)def
tabBarClicked(index)def
tabBarDoubleClicked(index)def
tabCloseRequested(index)
Detailed Description露
![]()
A tab widget provides a tab bar (see
QTabBar) and a 鈥減age 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 (seeTabPosition). 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()orinsertTab()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 bytabShape.The signal
currentChanged()is emitted when the user selects a page.The current page index is available as
currentIndex(), the current page widget withcurrentWidget(). You can retrieve a pointer to a page widget with a given index usingwidget(), and can find the index position of a widget withindexOf(). UsesetCurrentWidget()orsetCurrentIndex()to show a particular page.You can change a tab鈥檚 text and icon using
setTabText()orsetTabIcon(). A tab and its associated page can be removed withremoveTab().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, aQToolBaror aQListWidget.Most of the functionality in
QTabWidgetis provided by aQTabBar(at the top, providing the tabs) and aQStackedWidget(most of the area, organizing the individual pages).See also
- class PySide2.QtWidgets.QTabWidget([parent=None])露
- param parent:
Constructs a tabbed widget with parent
parent.
- PySide2.QtWidgets.QTabWidget.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.
- PySide2.QtWidgets.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.
- PySide2.QtWidgets.QTabWidget.addTab(widget, icon, label)露
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidgeticon 鈥
PySide2.QtGui.QIconlabel 鈥 str
- Return type:
int
This is an overloaded function.
Adds a tab with the given
page,icon, andlabelto the tab widget, and returns the index of the tab in the tab bar. Ownership ofpageis passed on to theQTabWidget.This function is the same as
addTab(), but with an additionalicon.
- PySide2.QtWidgets.QTabWidget.addTab(widget, arg__2)
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidgetarg__2 鈥 str
- Return type:
int
Adds a tab with the given
pageandlabelto the tab widget, and returns the index of the tab in the tab bar. Ownership ofpageis passed on to theQTabWidget.If the tab鈥檚
labelcontains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is 鈥淏ro&wse鈥 then Alt+W becomes a shortcut which will move the focus to this tab.Note
If you call 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 theupdatesEnabledproperty 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
- PySide2.QtWidgets.QTabWidget.clear()露
Removes all the pages, but does not delete them. Calling this function is equivalent to calling
removeTab()until the tab widget is empty.
- PySide2.QtWidgets.QTabWidget.cornerWidget([corner=Qt.TopRightCorner])露
- Parameters:
corner 鈥
Corner- Return type:
Returns the widget shown in the
cornerof the tab widget orNone.See also
- PySide2.QtWidgets.QTabWidget.count()露
- Return type:
int
This property holds the number of tabs in the tab bar.
By default, this property contains a value of 0.
- PySide2.QtWidgets.QTabWidget.currentChanged(index)露
- Parameters:
index 鈥 int
- PySide2.QtWidgets.QTabWidget.currentIndex()露
- Return type:
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.
- PySide2.QtWidgets.QTabWidget.currentWidget()露
- Return type:
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
- PySide2.QtWidgets.QTabWidget.documentMode()露
- Return type:
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.
See also
elideModedocumentModeusesScrollButtonsSH_TabBar_PreferNoArrows
- PySide2.QtWidgets.QTabWidget.elideMode()露
- Return type:
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.
See also
elideModeusesScrollButtonsSH_TabBar_ElideMode
- PySide2.QtWidgets.QTabWidget.iconSize()露
- Return type:
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
- PySide2.QtWidgets.QTabWidget.indexOf(widget)露
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidget- Return type:
int
Returns the index position of the page occupied by the widget
w, or -1 if the widget cannot be found.
- PySide2.QtWidgets.QTabWidget.initStyleOption(option)露
- Parameters:
Initialize
optionwith the values from thisQTabWidget. This method is useful for subclasses when they need aQStyleOptionTabWidgetFrame, but don鈥檛 want to fill in all the information themselves.See also
- PySide2.QtWidgets.QTabWidget.insertTab(index, widget, icon, label)露
- Parameters:
index 鈥 int
widget 鈥
PySide2.QtWidgets.QWidgeticon 鈥
PySide2.QtGui.QIconlabel 鈥 str
- Return type:
int
This is an overloaded function.
Inserts a tab with the given
label,page, andiconinto the tab widget at the specifiedindex, and returns the index of the inserted tab in the tab bar. Ownership ofpageis passed on to theQTabWidget.This function is the same as
insertTab(), but with an additionalicon.
- PySide2.QtWidgets.QTabWidget.insertTab(index, widget, arg__3)
- Parameters:
index 鈥 int
widget 鈥
PySide2.QtWidgets.QWidgetarg__3 鈥 str
- Return type:
int
Inserts a tab with the given
labelandpageinto the tab widget at the specifiedindex, and returns the index of the inserted tab in the tab bar. Ownership ofpageis passed on to theQTabWidget.The label is displayed in the tab and may vary in appearance depending on the configuration of the tab widget.
If the tab鈥檚
labelcontains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is 鈥淏ro&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 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 theupdatesEnabledproperty 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
- PySide2.QtWidgets.QTabWidget.isMovable()露
- Return type:
bool
This property holds This property holds whether the user can move the tabs within the tabbar area..
By default, this property is
false;
- PySide2.QtWidgets.QTabWidget.isTabEnabled(index)露
- Parameters:
index 鈥 int
- Return type:
bool
Returns
trueif the page at positionindexis enabled; otherwise returnsfalse.See also
- PySide2.QtWidgets.QTabWidget.isTabVisible(index)露
- Parameters:
index 鈥 int
- Return type:
bool
Returns true if the page at position
indexis visible; otherwise returns false.See also
- PySide2.QtWidgets.QTabWidget.removeTab(index)露
- Parameters:
index 鈥 int
Removes the tab at position
indexfrom this stack of widgets. The page widget itself is not deleted.See also
- PySide2.QtWidgets.QTabWidget.setCornerWidget(w[, corner=Qt.TopRightCorner])露
- Parameters:
corner 鈥
Corner
Sets the given
widgetto be shown in the specifiedcornerof the tab widget. The geometry of the widget is determined based on the widget鈥檚sizeHint()and thestyle().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
NorthandSouthtab positions; other orientations are known to not work properly.See also
- PySide2.QtWidgets.QTabWidget.setCurrentIndex(index)露
- Parameters:
index 鈥 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.
- PySide2.QtWidgets.QTabWidget.setCurrentWidget(widget)露
- Parameters:
widget 鈥
PySide2.QtWidgets.QWidget
Makes
widgetthe current widget. Thewidgetused must be a page in this tab widget.See also
- PySide2.QtWidgets.QTabWidget.setDocumentMode(set)露
- Parameters:
set 鈥 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.
See also
elideModedocumentModeusesScrollButtonsSH_TabBar_PreferNoArrows
- PySide2.QtWidgets.QTabWidget.setElideMode(mode)露
- Parameters:
mode 鈥
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.
See also
elideModeusesScrollButtonsSH_TabBar_ElideMode
- PySide2.QtWidgets.QTabWidget.setIconSize(size)露
- Parameters:
size 鈥
PySide2.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
- PySide2.QtWidgets.QTabWidget.setMovable(movable)露
- Parameters:
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;
- PySide2.QtWidgets.QTabWidget.setTabBar(arg__1)露
- Parameters:
arg__1 鈥
PySide2.QtWidgets.QTabBar
Replaces the dialog鈥檚
QTabBarheading with the tab bartb. Note that this must be called before any tabs have been added, or the behavior is undefined.See also
- PySide2.QtWidgets.QTabWidget.setTabBarAutoHide(enabled)露
- Parameters:
enabled 鈥 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
- PySide2.QtWidgets.QTabWidget.setTabEnabled(index, enabled)露
- Parameters:
index 鈥 int
enabled 鈥 bool
If
enableis true, the page at positionindexis enabled; otherwise the page at positionindexis disabled. The page鈥檚 tab is redrawn appropriately.QTabWidgetusessetEnabled()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
- PySide2.QtWidgets.QTabWidget.setTabIcon(index, icon)露
- Parameters:
index 鈥 int
icon 鈥
PySide2.QtGui.QIcon
Sets the
iconfor the tab at positionindex.See also
- PySide2.QtWidgets.QTabWidget.setTabPosition(position)露
- Parameters:
position 鈥
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
TabPosition
- PySide2.QtWidgets.QTabWidget.setTabShape(s)露
- Parameters:
s 鈥
TabShape
This property holds the shape of the tabs in this tab widget.
Possible values for this property are
Rounded(default) orTriangular.See also
TabShape
- PySide2.QtWidgets.QTabWidget.setTabText(index, text)露
- Parameters:
index 鈥 int
text 鈥 str
Defines a new
labelfor the page at positionindex鈥榮 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
QShortcutdocumentation for details (to display an actual ampersand, use 鈥&&鈥).See also
- PySide2.QtWidgets.QTabWidget.setTabToolTip(index, tip)露
- Parameters:
index 鈥 int
tip 鈥 str
Sets the tab tool tip for the page at position
indextotip.See also
- PySide2.QtWidgets.QTabWidget.setTabVisible(index, visible)露
- Parameters:
index 鈥 int
visible 鈥 bool
If
visibleis true, the page at positionindexis visible; otherwise the page at positionindexis hidden. The page鈥檚 tab is redrawn appropriately.See also
- PySide2.QtWidgets.QTabWidget.setTabWhatsThis(index, text)露
- Parameters:
index 鈥 int
text 鈥 str
Sets the What鈥檚 This help text for the page at position
indextotext.See also
- PySide2.QtWidgets.QTabWidget.setTabsClosable(closeable)露
- Parameters:
closeable 鈥 bool
This property holds whether close buttons are automatically added to each tab..
See also
- PySide2.QtWidgets.QTabWidget.setUsesScrollButtons(useButtons)露
- Parameters:
useButtons 鈥 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.
See also
elideModeusesScrollButtonsSH_TabBar_PreferNoArrows
- PySide2.QtWidgets.QTabWidget.tabBarAutoHide()露
- Return type:
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
- PySide2.QtWidgets.QTabWidget.tabBarClicked(index)露
- Parameters:
index 鈥 int
- PySide2.QtWidgets.QTabWidget.tabBarDoubleClicked(index)露
- Parameters:
index 鈥 int
- PySide2.QtWidgets.QTabWidget.tabCloseRequested(index)露
- Parameters:
index 鈥 int
- PySide2.QtWidgets.QTabWidget.tabIcon(index)露
- Parameters:
index 鈥 int
- Return type:
Returns the icon for the tab on the page at position
index.See also
- PySide2.QtWidgets.QTabWidget.tabInserted(index)露
- Parameters:
index 鈥 int
This virtual handler is called after a new tab was added or inserted at position
index.See also
- PySide2.QtWidgets.QTabWidget.tabPosition()露
- Return type:
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
TabPosition
- PySide2.QtWidgets.QTabWidget.tabRemoved(index)露
- Parameters:
index 鈥 int
This virtual handler is called after a tab was removed from position
index.See also
- PySide2.QtWidgets.QTabWidget.tabShape()露
- Return type:
This property holds the shape of the tabs in this tab widget.
Possible values for this property are
Rounded(default) orTriangular.See also
TabShape
- PySide2.QtWidgets.QTabWidget.tabText(index)露
- Parameters:
index 鈥 int
- Return type:
str
Returns the label text for the tab on the page at position
index.See also
- PySide2.QtWidgets.QTabWidget.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
- PySide2.QtWidgets.QTabWidget.tabWhatsThis(index)露
- Parameters:
index 鈥 int
- Return type:
str
Returns the What鈥檚 This help text for the page at position
index, or an empty string if no help text has been set.See also
- PySide2.QtWidgets.QTabWidget.tabsClosable()露
- Return type:
bool
This property holds whether close buttons are automatically added to each tab..
See also
- PySide2.QtWidgets.QTabWidget.usesScrollButtons()露
- Return type:
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.
See also
elideModeusesScrollButtonsSH_TabBar_PreferNoArrows
- PySide2.QtWidgets.QTabWidget.widget(index)露
- Parameters:
index 鈥 int
- Return type:
Returns the tab page at index position
indexorNoneif theindexis out of range.
漏 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.