QTabBar Class Reference

[ QtGui module]

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

继承 QWidget .

类型

方法

Special Methods

Qt Signals


详细描述

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

QTabBar is straightforward to use; it draws the tabs using one of the predefined shapes ,和 emits a signal when a tab is selected. It can be subclassed to tailor the look and feel. Qt also provides a ready-made QTabWidget .

每个选项卡有 tabText (), an optional tabIcon (),可选 tabToolTip (),可选 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 ().

Each tab can display text in a distinct color. The current text color for a tab can be found with the 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 () 和 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 , whereas 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.

Screenshot of a Plastique style tab bar A tab bar shown in the Plastique widget style.
Screenshot of a truncated Plastique tab bar A truncated tab bar shown in the Plastique widget style.

类型文档编制

QTabBar.ButtonPosition

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

常量 描述
QTabBar.LeftSide 0 选项卡的左侧。
QTabBar.RightSide 1 选项卡的右侧。

该枚举在 Qt 4.5 引入或被修改。

QTabBar.SelectionBehavior

此枚举类型列出了行为,为 QTabBar when a tab is removed and the tab being removed is also the current tab.

常量 描述
QTabBar.SelectLeftTab 0 Select the tab to the left of the one being removed.
QTabBar.SelectRightTab 1 Select the tab to the right of the one being removed.
QTabBar.SelectPreviousTab 2 选择先前选中的选项卡。

该枚举在 Qt 4.5 引入或被修改。

QTabBar.Shape

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

常量 描述
QTabBar.RoundedNorth 0 The normal rounded look above the pages
QTabBar.RoundedSouth 1 The normal rounded look below the pages
QTabBar.RoundedWest 2 The normal rounded look on the left side of the pages
QTabBar.RoundedEast 3 The normal rounded look on the right side the pages
QTabBar.TriangularNorth 4 在页面上方的三角形选项卡。
QTabBar.TriangularSouth 5 Triangular tabs similar to those used in the Excel spreadsheet, for example
QTabBar.TriangularWest 6 Triangular tabs on the left of the pages.
QTabBar.TriangularEast 7 Triangular tabs on the right of the 页面。

方法文档编制

QTabBar.__init__ ( self , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

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

int QTabBar.addTab ( self , QString  text )

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

int QTabBar.addTab ( self , QIcon   icon , QString  text )

这是重载函数。

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

QTabBar.changeEvent ( self , QEvent )

重实现自 QWidget.changeEvent ().

int QTabBar.count ( self )

int QTabBar.currentIndex ( self )

bool QTabBar.documentMode ( self )

bool QTabBar.drawBase ( self )

Qt.TextElideMode QTabBar.elideMode ( self )

bool QTabBar.event ( self , QEvent )

重实现自 QObject.event ().

bool QTabBar.expanding ( self )

QTabBar.hideEvent ( self , QHideEvent )

重实现自 QWidget.hideEvent ().

QSize QTabBar.iconSize ( self )

QTabBar.initStyleOption ( self , QStyleOptionTab   option , int  tabIndex )

初始化 option 采用值从选项卡在 tabIndex . This method is useful for subclasses when they need a QStyleOptionTab , QStyleOptionTabV2 ,或 QStyleOptionTabV3 but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionTab and fill in the additional values for a QStyleOptionTabV2 and QStyleOptionTabV3 .

另请参阅 QStyleOption.initFrom () 和 QTabWidget.initStyleOption ().

int QTabBar.insertTab ( self , int  index , QString  text )

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

int QTabBar.insertTab ( self , int  index , QIcon   icon , QString  text )

这是重载函数。

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

QTabBar was empty before this function is called, the inserted tab becomes the current tab.

Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current tab.

bool QTabBar.isMovable ( self )

bool QTabBar.isTabEnabled ( self , int  index )

返回 true 若选项卡在位置 index is enabled; otherwise returns false.

QTabBar.keyPressEvent ( self , QKeyEvent )

重实现自 QWidget.keyPressEvent ().

QSize QTabBar.minimumSizeHint ( self )

重实现自 QWidget.minimumSizeHint ().

QTabBar.mouseMoveEvent ( self , QMouseEvent )

重实现自 QWidget.mouseMoveEvent ().

QTabBar.mousePressEvent ( self , QMouseEvent )

重实现自 QWidget.mousePressEvent ().

QTabBar.mouseReleaseEvent ( self , QMouseEvent )

重实现自 QWidget.mouseReleaseEvent ().

QTabBar.moveTab ( self , int  from , int  to )

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

该函数在 Qt 4.5 引入。

另请参阅 tabMoved () and tabLayoutChange ().

QTabBar.paintEvent ( self , QPaintEvent )

重实现自 QWidget.paintEvent ().

QTabBar.removeTab ( self , int  index )

移除选项卡,在位置 index .

另请参阅 SelectionBehavior .

QTabBar.resizeEvent ( self , QResizeEvent )

重实现自 QWidget.resizeEvent ().

SelectionBehavior QTabBar.selectionBehaviorOnRemove ( self )

QTabBar.setCurrentIndex ( self , int  index )

This method is also a Qt slot with the C++ signature void setCurrentIndex(int) .

QTabBar.setDocumentMode ( self , bool  set )

QTabBar.setDrawBase ( self , bool  drawTheBase )

QTabBar.setElideMode ( self , Qt.TextElideMode )

QTabBar.setExpanding ( self , bool  enabled )

QTabBar.setIconSize ( self , QSize   size )

QTabBar.setMovable ( self , bool  movable )

QTabBar.setSelectionBehaviorOnRemove ( self , SelectionBehavior   behavior )

QTabBar.setShape ( self , 形状   shape )

QTabBar.setTabButton ( self , int  index , ButtonPosition   position , QWidget   widget )

widget argument has it's ownership transferred to Qt.

widget 在选项卡 index . The widget is placed on the left or right hand side depending upon the position .

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

The tab bar will take ownership of the widget and so all widgets set here will be deleted by the tab bar when it is destroyed unless you separately reparent the widget after setting some other widget (or 0).

该函数在 Qt 4.5 引入。

另请参阅 tabButton () and tabsClosable ().

QTabBar.setTabData ( self , int  index , QVariant  data )

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

另请参阅 tabData ().

QTabBar.setTabEnabled ( self , int  index , bool)

enabled 为 true 则选项卡在位置 index 被启用;否则项在位置 index is disabled.

另请参阅 isTabEnabled ().

QTabBar.setTabIcon ( self , int  index , QIcon   icon )

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

另请参阅 tabIcon ().

QTabBar.setTabsClosable ( self , bool  closable )

QTabBar.setTabText ( self , int  index , QString  text )

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

另请参阅 tabText ().

QTabBar.setTabTextColor ( self , int  index , QColor   color )

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

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

另请参阅 tabTextColor ().

QTabBar.setTabToolTip ( self , int  index , QString  tip )

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

另请参阅 tabToolTip ().

QTabBar.setTabWhatsThis ( self , int  index , QString  text )

设置选项卡的 What's This 帮助文本,在位置 index to text .

该函数在 Qt 4.1 引入。

另请参阅 tabWhatsThis ().

QTabBar.setUsesScrollButtons ( self , bool  useButtons )

形状 QTabBar.shape ( self )

QTabBar.showEvent ( self , QShowEvent )

重实现自 QWidget.showEvent ().

QSize QTabBar.sizeHint ( self )

重实现自 QWidget.sizeHint ().

int QTabBar.tabAt ( self , QPoint   pos )

返回选项卡索引,覆盖 position or -1 if no tab covers position ;

该函数在 Qt 4.3 引入。

QWidget QTabBar.tabButton ( self , int  index , ButtonPosition   position )

返回 Widget 设置选项卡 index and position or 0 if one is not set.

另请参阅 setTabButton ().

QVariant QTabBar.tabData ( self , int  index )

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

另请参阅 setTabData ().

QIcon QTabBar.tabIcon ( self , int  index )

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

另请参阅 setTabIcon ().

QTabBar.tabInserted ( self , int  index )

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

另请参阅 tabRemoved ().

QTabBar.tabLayoutChange ( self )

This virtual handler is called whenever the tab layout 改变。

另请参阅 tabRect ().

QRect QTabBar.tabRect ( self , int  index )

返回选项卡的视觉矩形,在位置 index ,或 null 矩形若 index is out of range.

QTabBar.tabRemoved ( self , int  index )

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

另请参阅 tabInserted ().

bool QTabBar.tabsClosable ( self )

QSize QTabBar.tabSizeHint ( self , int  index )

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

QString QTabBar.tabText ( self , int  index )

返回选项卡的文本,在位置 index ,或 empty string if index 超出范围。

另请参阅 setTabText ().

QColor QTabBar.tabTextColor ( self , int  index )

返回选项卡的文本颜色,采用给定 index , or a invalid color if index 超出范围。

另请参阅 setTabTextColor ().

QString QTabBar.tabToolTip ( self , int  index )

返回选项卡的工具提示,在位置 index ,或 empty string if index 超出范围。

另请参阅 setTabToolTip ().

QString QTabBar.tabWhatsThis ( self , int  index )

返回选项卡的 What's This 帮助文本,在位置 index ,或空字符串若 index is out of range.

该函数在 Qt 4.1 引入。

另请参阅 setTabWhatsThis ().

bool QTabBar.usesScrollButtons ( self )

QTabBar.wheelEvent ( self , QWheelEvent   event )

重实现自 QWidget.wheelEvent ().

QTabBar.__len__ ( self )


Qt Signal Documentation

void currentChanged (int)

This is the default overload of this signal.

This signal is emitted when the tab bar's current tab changes. The new current has the given index , or -1 if there isn't a new one (for example, if there are no tab in the QTabBar )

void tabCloseRequested (int)

This is the default overload of this signal.

This signal is emitted when the close button on a tab is clicked. The index 是应被移除的索引。

该函数在 Qt 4.5 引入。

另请参阅 setTabsClosable ().

void tabMoved (int,int)

This is the default overload of this signal.

This signal is emitted when the tab has moved the tab at index position from 到索引位置 to .

注意: QTabWidget will automatically move the page when this signal is emitted from its tab bar.

该函数在 Qt 4.5 引入。

另请参阅 moveTab ().