内容表

上一话题

QTabBar

下一话题

QTableView

QTabWidget

QTabWidget class provides a stack of tabbed widgets. 更多

Inheritance diagram of PySide2.QtWidgets.QTabWidget

概要

函数

虚函数

信号

详细描述

../../_images/windows-tabwidget.png

选项卡小部件提供选项卡栏 (见 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 QTabWidget is to do the following:

  1. 创建 QTabWidget .

  2. 创建 QWidget 对于每选项卡对话框页面,但不要为它们指定父级小部件。

  3. 将子级 Widget 插入页面小部件,使用布局正常安放它们。

  4. 调用 addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.

选项卡位置的定义通过 tabPosition ,它们的形状通过 tabShape .

信号 currentChanged() is emitted when the user selects a page.

当前页面索引可用作 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() 。使用 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() .

可以随时启用或禁用每选项卡 (见 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.

选项卡小部件可以是拆分复杂对话框的很好方式。另一方式是使用 QStackedWidget 提供在页面之间导航的一些手段,例如 QToolBar QListWidget .

Most of the functionality in QTabWidget is provided by a QTabBar (在顶部,提供选项卡) 和 QStackedWidget (大部分区域,组织各个页面)。

class QTabWidget ( [ parent=None ] )
param parent

QWidget

构造选项卡式 Widget 采用父级 parent .

PySide2.QtWidgets.QTabWidget. TabPosition

此枚举类型定义在哪里 QTabWidget 绘制选项卡行:

常量

描述

QTabWidget.North

选项卡绘制在页面上方。

QTabWidget.South

选项卡绘制在页面下方。

QTabWidget.West

选项卡绘制在页面左侧。

QTabWidget.East

选项卡绘制在页面右侧。

PySide2.QtWidgets.QTabWidget. TabShape

此枚举类型定义选项卡的形状:

常量

描述

QTabWidget.Rounded

选项卡采用圆角外观绘制。这是默认形状。

QTabWidget.Triangular

选项卡采用三角形外观绘制。

PySide2.QtWidgets.QTabWidget. addTab ( widget , icon , label )
参数
  • widget QWidget

  • icon QIcon

  • label – unicode

返回类型

int

这是重载函数。

添加选项卡采用给定 page , icon ,和 label 到选项卡 Widget,并返回选项卡在选项卡栏中的索引。所有权为 page 被传递给 QTabWidget .

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

PySide2.QtWidgets.QTabWidget. addTab ( widget , arg__2 )
参数
返回类型

int

添加选项卡采用给定 page and label 到选项卡 Widget,并返回选项卡在选项卡栏中的索引。所有权为 page 被传递给 QTabWidget .

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 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 the updatesEnabled 特性为 false 在改变前;记得设置特性为 true 当改变完成后,使小部件再次接收描绘事件。

另请参阅

insertTab()

PySide2.QtWidgets.QTabWidget. clear ( )

移除所有页面,但不删除它们。调用此函数相当于调用 removeTab() until the tab widget is empty.

PySide2.QtWidgets.QTabWidget. cornerWidget ( [ corner=Qt.TopRightCorner ] )
参数

corner Corner

返回类型

QWidget

返回的 Widget 展示在 corner 对于选项卡小部件或 None .

另请参阅

setCornerWidget()

PySide2.QtWidgets.QTabWidget. count ( )
返回类型

int

PySide2.QtWidgets.QTabWidget. currentChanged ( index )
参数

index int

PySide2.QtWidgets.QTabWidget. currentIndex ( )
返回类型

int

另请参阅

setCurrentIndex()

PySide2.QtWidgets.QTabWidget. currentWidget ( )
返回类型

QWidget

返回由选项卡对话框所显示的目前页面指针。选项卡对话框会尽力确保此值从不为 0 (但若足够努力,可以)。

PySide2.QtWidgets.QTabWidget. documentMode ( )
返回类型

bool

另请参阅

setDocumentMode()

PySide2.QtWidgets.QTabWidget. elideMode ( )
返回类型

TextElideMode

另请参阅

setElideMode()

PySide2.QtWidgets.QTabWidget. iconSize ( )
返回类型

QSize

另请参阅

setIconSize()

PySide2.QtWidgets.QTabWidget. indexOf ( widget )
参数

widget QWidget

返回类型

int

返回页面占据的索引位置由 Widget w ,或 -1 若找不到 Widget。

PySide2.QtWidgets.QTabWidget. initStyleOption ( option )
参数

option QStyleOptionTabWidgetFrame

初始化 option 采用值来自此 QTabWidget 。此方法对子类是有用的,当需要 QStyleOptionTabWidgetFrame , but don’t want to fill in all the information themselves.

PySide2.QtWidgets.QTabWidget. insertTab ( index , widget , icon , label )
参数
  • index int

  • widget QWidget

  • icon QIcon

  • label – unicode

返回类型

int

这是重载函数。

插入选项卡采用给定 label , page ,和 icon 到选项卡小部件在指定 index ,并返回插入在选项卡栏中的选项卡索引。所有权在 page 被传递给 QTabWidget .

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

PySide2.QtWidgets.QTabWidget. insertTab ( index , widget , arg__3 )
参数
  • index int

  • widget QWidget

  • arg__3 – unicode

返回类型

int

插入选项卡采用给定 label and page 到选项卡小部件在指定 index ,并返回插入在选项卡栏中的选项卡索引。所有权在 page 被传递给 QTabWidget .

标签显示在选项卡中且外观可能有所不同,从属选项卡小部件配置。

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.

index 超出范围,只需追加选项卡。否则,将其插入在指定位置。

QTabWidget 为空在调用此函数之前,新页面变为当前页面。在 <= 当前索引的索引处插入新选项卡将递增当前索引,但保持当前页面。

注意

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 the updatesEnabled 特性为 false 在改变前;记得设置特性为 true 当改变完成后,使小部件再次接收描绘事件。

另请参阅

addTab()

PySide2.QtWidgets.QTabWidget. isMovable ( )
返回类型

bool

PySide2.QtWidgets.QTabWidget. isTabEnabled ( index )
参数

index int

返回类型

bool

返回 true 若页面在位置 index 被启用;否则返回 false .

PySide2.QtWidgets.QTabWidget. isTabVisible ( index )
参数

index int

返回类型

bool

返回 true 若页面在位置 index 可见;否则返回 false。

另请参阅

setTabVisible()

PySide2.QtWidgets.QTabWidget. removeTab ( index )
参数

index int

移除选项卡,在位置 index 从此 Widget 堆栈。页面 Widget 本身未被删除。

PySide2.QtWidgets.QTabWidget. setCornerWidget ( w [ , corner=Qt.TopRightCorner ] )
参数

设置给定 widget 以展示在指定 corner of the tab widget. The geometry of the widget is determined based on the widget’s sizeHint() style() .

仅水平元素的 corner 会被使用。

传递 None 不展示角落 Widget。

任何先前设置的角落 Widget 均被隐藏。

选项卡小部件会删除此处设置的所有 Widget 当销毁它时,除非单独重设小部件父级先于设置一些其它角落小部件 (或 None ).

注意:角落小部件被设计为 North and South 选项卡位置;其它已知取向工作不正确。

PySide2.QtWidgets.QTabWidget. setCurrentIndex ( index )
参数

index int

另请参阅

currentIndex()

PySide2.QtWidgets.QTabWidget. setCurrentWidget ( widget )
参数

widget QWidget

Makes widget 当前小部件。 widget 使用的必须是此选项卡小部件的页面。

PySide2.QtWidgets.QTabWidget. setDocumentMode ( set )
参数

set bool

另请参阅

documentMode()

PySide2.QtWidgets.QTabWidget. setElideMode ( mode )
参数

mode TextElideMode

另请参阅

elideMode()

PySide2.QtWidgets.QTabWidget. setIconSize ( size )
参数

size QSize

另请参阅

iconSize()

PySide2.QtWidgets.QTabWidget. setMovable ( movable )
参数

movable bool

另请参阅

isMovable()

PySide2.QtWidgets.QTabWidget. setTabBar ( arg__1 )
参数

arg__1 QTabBar

Replaces the dialog’s QTabBar 头采用选项卡栏 tb 。注意,这必须被调用 before 任何选项卡被添加,或行为不确定。

另请参阅

tabBar()

PySide2.QtWidgets.QTabWidget. setTabBarAutoHide ( enabled )
参数

enabled bool

另请参阅

tabBarAutoHide()

PySide2.QtWidgets.QTabWidget. setTabEnabled ( index , enabled )
参数
  • index int

  • enabled bool

enable 为 true,页面在位置 index 被启用;否则页面在位置 index is disabled. The page’s tab is redrawn appropriately.

QTabWidget 使用 setEnabled() internally, rather than keeping a separate flag.

注意,即使选项卡/页面被禁用也可能可见。若页面已经可见, QTabWidget 不会隐藏它;若所有页面被禁用, QTabWidget 将展示它们之一。

PySide2.QtWidgets.QTabWidget. setTabIcon ( index , icon )
参数
  • index int

  • icon QIcon

设置 icon 为选项卡在位置 index .

另请参阅

tabIcon()

PySide2.QtWidgets.QTabWidget. setTabPosition ( position )
参数

position TabPosition

另请参阅

tabPosition()

PySide2.QtWidgets.QTabWidget. setTabShape ( s )
参数

s TabShape

另请参阅

tabShape()

PySide2.QtWidgets.QTabWidget. setTabText ( index , text )
参数
  • index int

  • text – unicode

定义新 label 为页面,在位置 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 ‘&&’).

另请参阅

tabText()

PySide2.QtWidgets.QTabWidget. setTabToolTip ( index , tip )
参数
  • index int

  • tip – unicode

设置选项卡工具提示为页面,在位置 index to tip .

另请参阅

tabToolTip()

PySide2.QtWidgets.QTabWidget. setTabVisible ( index , visible )
参数
  • index int

  • visible bool

visible 为 true,页面在位置 index 是可见的;否则页面在位置 index is hidden. The page’s tab is redrawn appropriately.

另请参阅

isTabVisible()

PySide2.QtWidgets.QTabWidget. setTabWhatsThis ( index , text )
参数
  • index int

  • text – unicode

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

另请参阅

tabWhatsThis()

PySide2.QtWidgets.QTabWidget. setTabsClosable ( closeable )
参数

closeable bool

另请参阅

tabsClosable()

PySide2.QtWidgets.QTabWidget. setUsesScrollButtons ( useButtons )
参数

useButtons bool

PySide2.QtWidgets.QTabWidget. tabBar ( )
返回类型

QTabBar

返回当前 QTabBar .

另请参阅

setTabBar()

PySide2.QtWidgets.QTabWidget. tabBarAutoHide ( )
返回类型

bool

PySide2.QtWidgets.QTabWidget. tabBarClicked ( index )
参数

index int

PySide2.QtWidgets.QTabWidget. tabBarDoubleClicked ( index )
参数

index int

PySide2.QtWidgets.QTabWidget. tabCloseRequested ( index )
参数

index int

PySide2.QtWidgets.QTabWidget. tabIcon ( index )
参数

index int

返回类型

QIcon

返回页面选项卡图标,在位置 index .

另请参阅

setTabIcon()

PySide2.QtWidgets.QTabWidget. tabInserted ( index )
参数

index int

调用此虚拟处理程序,在添加或插入新选项卡后于位置 index .

另请参阅

tabRemoved()

PySide2.QtWidgets.QTabWidget. tabPosition ( )
返回类型

TabPosition

另请参阅

setTabPosition()

PySide2.QtWidgets.QTabWidget. tabRemoved ( index )
参数

index int

此虚拟处理程序被调用,在选项卡被移除后从位置 index .

另请参阅

tabInserted()

PySide2.QtWidgets.QTabWidget. tabShape ( )
返回类型

TabShape

另请参阅

setTabShape()

PySide2.QtWidgets.QTabWidget. tabText ( index )
参数

index int

返回类型

unicode

返回页面选项卡标签文本,在位置 index .

另请参阅

setTabText()

PySide2.QtWidgets.QTabWidget. tabToolTip ( index )
参数

index int

返回类型

unicode

返回页面选项卡工具提示,在位置 index 或空字符串若未设置工具提示。

另请参阅

setTabToolTip()

PySide2.QtWidgets.QTabWidget. tabWhatsThis ( index )
参数

index int

返回类型

unicode

Returns the What’s This help text for the page at position index ,或空字符串若未设置帮助文本。

另请参阅

setTabWhatsThis()

PySide2.QtWidgets.QTabWidget. tabsClosable ( )
返回类型

bool

另请参阅

setTabsClosable()

PySide2.QtWidgets.QTabWidget. usesScrollButtons ( )
返回类型

bool

PySide2.QtWidgets.QTabWidget. widget ( index )
参数

index int

返回类型

QWidget

返回选项卡页面,在索引位置 index or None index 超出范围。