内容表

上一话题

QSystemTrayIcon

下一话题

QTabWidget

QTabBar

QTabBar class provides a tab bar, e.g. for use in tabbed dialogs. 更多

Inheritance diagram of PySide2.QtWidgets.QTabBar

概要

函数

虚函数

信号

详细描述

QTabBar is straightforward to use; it draws the tabs using one of the predefined shapes ,并发射信号,当选项卡被选中时。它可以被子类化以订制外观和感觉。Qt 还提供现成 QTabWidget .

每个选项卡有 tabText() , an optional tabIcon() , an optional tabToolTip() , optional tabWhatsThis() 和可选 tabData() . The tabs’s attributes can be changed with setTabText() , setTabIcon() , setTabToolTip() , setTabWhatsThis and setTabData() . Each tabs can be enabled or disabled individually with setTabEnabled() .

每个选项卡可以按截然不同颜色显示文本。可以找到当前选项卡的文本颜色采用 tabTextColor() function. Set the text color for a particular tab with setTabTextColor() .

添加选项卡使用 addTab() , or inserted at particular positions using insertTab() . The total number of tabs is given by count() . Tabs can be removed from the tab bar with removeTab() . Combining removeTab() and insertTab() allows you to move tabs to different positions.

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 ,而 RoundedSouth is used mostly when the pages are different (e.g. a multi-page tool palette). The default in QTabBar is RoundedNorth .

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

QTabBar creates automatic mnemonic keys in the manner of 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:

对于子类,可能还需要 tabRect() functions which returns the visual geometry of a single tab.

fusion-tabbar1

选项卡栏展示在 融合 Widget 风格 .

fusion-tabbar-truncated2

以 Fusion 小部件样式展示截取选项卡栏。

另请参阅

QTabWidget

class QTabBar ( [ parent=None ] )
param parent

QWidget

创建新的选项卡栏,采用给定 parent .

PySide2.QtWidgets.QTabBar. 形状

此枚举类型列出了受支持的内置形状,由 QTabBar . Treat these as hints as some styles may not render some of the shapes. However, position should be honored.

常量

描述

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

在页面上方的三角形选项卡。

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.

PySide2.QtWidgets.QTabBar. ButtonPosition

此枚举类型列表 Widget 在选项卡上的位置。

常量

描述

QTabBar.LeftSide

选项卡的左侧。

QTabBar.RightSide

选项卡的右侧。

PySide2.QtWidgets.QTabBar. SelectionBehavior

此枚举类型列表行为在 QTabBar 当选项卡被移除且被移除选项卡也是当前选项卡时。

常量

描述

QTabBar.SelectLeftTab

选择被移除选项卡左侧的选项卡。

QTabBar.SelectRightTab

选择被移除选项卡右侧的选项卡。

QTabBar.SelectPreviousTab

选择先前选中的选项卡。

PySide2.QtWidgets.QTabBar. accessibleTabName ( index )
参数

index int

返回类型

unicode

返回 accessibleName 对于选项卡在位置 index ,或空字符串若 index 超出范围。

PySide2.QtWidgets.QTabBar. addTab ( icon , text )
参数
  • icon QIcon

  • text – unicode

返回类型

int

这是重载函数。

添加新选项卡采用图标 icon 和文本 text . Returns the new tab’s index.

PySide2.QtWidgets.QTabBar. addTab ( text )
参数

text – unicode

返回类型

int

添加新选项卡采用文本 text . Returns the new tab’s index.

PySide2.QtWidgets.QTabBar. autoHide ( )
返回类型

bool

另请参阅

setAutoHide()

PySide2.QtWidgets.QTabBar. changeCurrentOnDrag ( )
返回类型

bool

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

int

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

index int

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

int

另请参阅

setCurrentIndex()

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

bool

另请参阅

setDocumentMode()

PySide2.QtWidgets.QTabBar. drawBase ( )
返回类型

bool

另请参阅

setDrawBase()

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

TextElideMode

另请参阅

setElideMode()

PySide2.QtWidgets.QTabBar. expanding ( )
返回类型

bool

另请参阅

setExpanding()

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

QSize

另请参阅

setIconSize()

PySide2.QtWidgets.QTabBar. initStyleOption ( option , tabIndex )
参数

初始化 option 采用值从选项卡在 tabIndex 。此方法对子类是有用的,当需要 QStyleOptionTab , but don’t want to fill in all the information themselves.

PySide2.QtWidgets.QTabBar. insertTab ( index , icon , text )
参数
  • index int

  • icon QIcon

  • text – unicode

返回类型

int

这是重载函数。

插入新选项卡采用图标 icon 和文本 text 在位置 index 。若 index is out of range, the new tab is appended. Returns the new tab’s index.

QTabBar 为空在调用此函数之前,插入选项卡变为当前选项卡。

在 <= 当前索引的索引处插入新选项卡将递增当前索引,但保持当前选项卡。

PySide2.QtWidgets.QTabBar. insertTab ( index , text )
参数
  • index int

  • text – unicode

返回类型

int

插入新选项卡采用文本 text 在位置 index 。若 index is out of range, the new tab is appened. Returns the new tab’s index.

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

bool

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

index int

返回类型

bool

返回 true 若选项卡在位置 index 被启用;否则返回 false .

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

index int

返回类型

bool

返回 true 若选项卡在位置 index 可见;否则返回 false。

PySide2.QtWidgets.QTabBar. minimumTabSizeHint ( index )
参数

index int

返回类型

QSize

返回最小选项卡尺寸提示,对于选项卡在位置 index .

PySide2.QtWidgets.QTabBar. moveTab ( from , to )
参数
  • from int

  • to int

移动索引位置项 from 到索引位置 to .

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

index int

移除选项卡,在位置 index .

另请参阅

SelectionBehavior

PySide2.QtWidgets.QTabBar. selectionBehaviorOnRemove ( )
返回类型

SelectionBehavior

PySide2.QtWidgets.QTabBar. setAccessibleTabName ( index , name )
参数
  • index int

  • name – unicode

设置 accessibleName 对于选项卡在位置 index to name .

PySide2.QtWidgets.QTabBar. setAutoHide ( hide )
参数

hide bool

另请参阅

autoHide()

PySide2.QtWidgets.QTabBar. setChangeCurrentOnDrag ( change )
参数

change bool

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

index int

另请参阅

currentIndex()

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

set bool

另请参阅

documentMode()

PySide2.QtWidgets.QTabBar. setDrawBase ( drawTheBase )
参数

drawTheBase bool

另请参阅

drawBase()

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

mode TextElideMode

另请参阅

elideMode()

PySide2.QtWidgets.QTabBar. setExpanding ( enabled )
参数

enabled bool

另请参阅

expanding()

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

size QSize

另请参阅

iconSize()

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

movable bool

另请参阅

isMovable()

PySide2.QtWidgets.QTabBar. setSelectionBehaviorOnRemove ( behavior )
参数

behavior SelectionBehavior

PySide2.QtWidgets.QTabBar. setShape ( shape )
参数

shape 形状

另请参阅

shape()

PySide2.QtWidgets.QTabBar. setTabButton ( index , position , widget )
参数

widget 在选项卡 index 。Widget 被放置在左侧或右侧从属 position .

任何先前设置 Widget 在 position 被隐藏。

选项卡栏将拥有小部件的所有权,因此,选项卡栏会删除此处设置的所有小部件当销毁时,除非单独重设 Widget 父级在设置一些其它小部件后 (或 None ).

PySide2.QtWidgets.QTabBar. setTabData ( index , data )
参数
  • index int

  • data – object

设置选项卡的数据,在位置 index to data .

另请参阅

tabData()

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

  • enabled bool

enabled 为 true 则选项卡在位置 index 被启用;否则项在位置 index 是禁用的。

另请参阅

isTabEnabled()

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

  • icon QIcon

设置选项卡的图标,在位置 index to icon .

另请参阅

tabIcon()

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

  • text – unicode

设置选项卡的文本,在位置 index to text .

另请参阅

tabText()

PySide2.QtWidgets.QTabBar. setTabTextColor ( index , color )
参数
  • index int

  • color QColor

设置选项卡文本颜色采用给定 index 到指定 color .

如果指定的是无效颜色,选项卡将使用 QTabBar 前景角色代替。

另请参阅

tabTextColor()

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

  • tip – unicode

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

另请参阅

tabToolTip()

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

  • visible bool

visible 为 true,使选项卡在位置 index 可见,否则使之隐藏。

另请参阅

isTabVisible()

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

  • text – unicode

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

另请参阅

tabWhatsThis()

PySide2.QtWidgets.QTabBar. setTabsClosable ( closable )
参数

closable bool

另请参阅

tabsClosable()

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

useButtons bool

PySide2.QtWidgets.QTabBar. shape ( )
返回类型

形状

另请参阅

setShape()

PySide2.QtWidgets.QTabBar. tabAt ( pos )
参数

pos QPoint

返回类型

int

返回选项卡索引,覆盖 position 或 -1 若没有选项卡覆盖 position ;

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

index int

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

index int

PySide2.QtWidgets.QTabBar. tabButton ( index , position )
参数
返回类型

QWidget

返回 Widget 设置选项卡 index and position or None 若尚未设置一个。

另请参阅

setTabButton()

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

index int

PySide2.QtWidgets.QTabBar. tabData ( index )
参数

index int

返回类型

object

返回选项卡的数据,在位置 index ,或 null 变体若 index 超出范围。

另请参阅

setTabData()

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

index int

返回类型

QIcon

返回选项卡的图标,在位置 index ,或 null 图标若 index 超出范围。

另请参阅

setTabIcon()

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

index int

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

另请参阅

tabRemoved()

PySide2.QtWidgets.QTabBar. tabLayoutChange ( )

此虚拟处理程序被调用,每当选项卡布局改变时。

另请参阅

tabRect()

PySide2.QtWidgets.QTabBar. tabMoved ( from , to )
参数
  • from int

  • to int

PySide2.QtWidgets.QTabBar. tabRect ( index )
参数

index int

返回类型

QRect

返回选项卡的视觉矩形,在位置 index ,或 null 矩形若 index 被隐藏或超出范围。

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

index int

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

另请参阅

tabInserted()

PySide2.QtWidgets.QTabBar. tabSizeHint ( index )
参数

index int

返回类型

QSize

返回选项卡大小提示,在位置 index .

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

index int

返回类型

unicode

返回选项卡的文本,在位置 index ,或空字符串若 index 超出范围。

另请参阅

setTabText()

PySide2.QtWidgets.QTabBar. tabTextColor ( index )
参数

index int

返回类型

QColor

返回选项卡的文本颜色,采用给定 index ,或无效颜色若 index 超出范围。

另请参阅

setTabTextColor()

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

index int

返回类型

unicode

返回选项卡的工具提示,在位置 index ,或空字符串若 index 超出范围。

另请参阅

setTabToolTip()

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

index int

返回类型

unicode

Returns the What’s This help text of the tab at position index ,或空字符串若 index 超出范围。

另请参阅

setTabWhatsThis()

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

bool

另请参阅

setTabsClosable()

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

bool