QTabBar 类

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

头: #include <QTabBar>
qmake: QT += widgets
继承: QWidget

公共类型

enum ButtonPosition { LeftSide, RightSide }
enum SelectionBehavior { SelectLeftTab, SelectRightTab, SelectPreviousTab }
enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, ..., TriangularEast }

特性

公共函数

QTabBar (QWidget * parent = Q_NULLPTR)
~QTabBar ()
QString accessibleTabName (int index ) const
int addTab (const QString & text )
int addTab (const QIcon & icon , const QString & text )
bool autoHide () const
bool changeCurrentOnDrag () const
int count () const
int currentIndex () const
bool documentMode () const
bool drawBase () const
Qt::TextElideMode elideMode () const
bool expanding () const
QSize iconSize () const
int insertTab (int index , const QString & text )
int insertTab (int index , const QIcon & icon , const QString & text )
bool isMovable () const
bool isTabEnabled (int index ) const
void moveTab (int from , int to )
void removeTab (int index )
SelectionBehavior selectionBehaviorOnRemove () const
void setAccessibleTabName (int index , const QString & name )
void setAutoHide (bool hide )
void setChangeCurrentOnDrag (bool change )
void setDocumentMode (bool set )
void setDrawBase (bool drawTheBase )
void setElideMode ( Qt::TextElideMode )
void setExpanding (bool enabled )
void setIconSize (const QSize & size )
void setMovable (bool movable )
void setSelectionBehaviorOnRemove (SelectionBehavior behavior )
void setShape (Shape shape )
void setTabButton (int index , ButtonPosition position , QWidget * widget )
void setTabData (int index , const QVariant & data )
void setTabEnabled (int index , bool enabled )
void setTabIcon (int index , const QIcon & icon )
void setTabText (int index , const QString & text )
void setTabTextColor (int index , const QColor & color )
void setTabToolTip (int index , const QString & tip )
void setTabWhatsThis (int index , const QString & text )
void setTabsClosable (bool closable )
void setUsesScrollButtons (bool useButtons )
形状 shape () const
int tabAt (const QPoint & position ) const
QWidget * tabButton (int index , ButtonPosition position ) const
QVariant tabData (int index ) const
QIcon tabIcon (int index ) const
QRect tabRect (int index ) const
QString tabText (int index ) const
QColor tabTextColor (int index ) const
QString tabToolTip (int index ) const
QString tabWhatsThis (int index ) const
bool tabsClosable () const
bool usesScrollButtons () const

重实现公共函数

virtual QSize minimumSizeHint () const
virtual QSize sizeHint () const

公共槽

void setCurrentIndex (int index )

信号

void currentChanged (int index )
void tabBarClicked (int index )
void tabBarDoubleClicked (int index )
void tabCloseRequested (int index )
void tabMoved (int from , int to )

保护函数

void initStyleOption (QStyleOptionTab * option , int tabIndex ) const
virtual QSize minimumTabSizeHint (int index ) const
virtual void tabInserted (int index )
virtual void tabLayoutChange ()
virtual void tabRemoved (int index )
virtual QSize tabSizeHint (int index ) const

重实现保护函数

virtual void changeEvent (QEvent * event )
virtual bool event (QEvent * event )
virtual void hideEvent ( QHideEvent * )
virtual void keyPressEvent (QKeyEvent * event )
virtual void mouseMoveEvent (QMouseEvent * event )
virtual void mousePressEvent (QMouseEvent * event )
virtual void mouseReleaseEvent (QMouseEvent * event )
virtual void paintEvent ( QPaintEvent * )
virtual void resizeEvent ( QResizeEvent * )
virtual void showEvent ( QShowEvent * )
virtual void timerEvent (QTimerEvent * event )
virtual void wheelEvent (QWheelEvent * event )

额外继承成员

详细描述

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 ,并发射信号,当选项卡被选中时。它可以被子类化以订制外观和感觉。Qt 还提供现成 QTabWidget .

每个选项卡有 tabText (),可选 tabIcon (),可选 tabToolTip (),可选 tabWhatsThis () 和可选 tabData ()。可以改变选项卡属性采用 setTabText (), setTabIcon (), setTabToolTip (), setTabWhatsThis and setTabData ()。每个选项卡可以被单独启用或禁用采用 setTabEnabled ().

每个选项卡可以按截然不同颜色显示文本。可以找到当前选项卡的文本颜色采用 tabTextColor () 函数。设置用于特定选项卡的文本颜色采用 setTabTextColor ().

添加选项卡使用 addTab (),或插入在特定位置使用 insertTab ()。选项卡总数的给出通过 count ()。可以从选项卡栏移除选项卡采用 removeTab ()。组合 removeTab () 和 insertTab () 允许将选项卡移动到不同位置。

shape 特性定义选项卡的外观。形状的选择是品味问题,尽管选项卡对话框 (对于首选项和类似的) 始终不变使用 RoundedNorth 。窗口 (除对话框外) 中的选项卡控件几乎总是使用 RoundedSouth or TriangularSouth 。许多电子表格和其它所有页面基本类似的选项卡控件使用 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 () 信号。这被发射每当当前选项卡改变时 (即使在启动时,当当前选项卡从 none 改变时)。还有槽, setCurrentIndex () 可以用于以编程方式选择选项卡。函数 currentIndex () 返回当前选项卡的索引, count 保存选项卡的数量。

QTabBar creates automatic mnemonic keys in the manner of QAbstractButton ;如:若选项卡的标签为 &Graphics,Alt+G 将变为切换到该选项卡的快捷键。

可能需要重实现以下虚函数,为每个选项卡订制外观和感觉或存储额外数据:

对于子类,可能还需要 tabRect () 函数返回单个选项卡的视觉几何体。

Screenshot of a Fusion style tab bar 选项卡栏展示在 Fusion 小部件风格 .
Screenshot of a truncated Fusion tab bar 以 Fusion 小部件样式展示截取选项卡栏。

另请参阅 QTabWidget .

成员类型文档编制

enum QTabBar:: ButtonPosition

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

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

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

enum QTabBar:: SelectionBehavior

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

常量 描述
QTabBar::SelectLeftTab 0 选择被移除选项卡左侧的选项卡。
QTabBar::SelectRightTab 1 选择被移除选项卡右侧的选项卡。
QTabBar::SelectPreviousTab 2 选择先前选中的选项卡。

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

enum QTabBar:: Shape

此枚举类型列出的内置形状支持通过 QTabBar 。视这些为提示,因为某些样式可能无法渲染某些形状。不管怎样,位置应该被承兑。

常量 描述
QTabBar::RoundedNorth 0 在页面上方的正常圆角外观
QTabBar::RoundedSouth 1 在页面下方的正常圆角外观
QTabBar::RoundedWest 2 在页面左侧的正常圆角外观
QTabBar::RoundedEast 3 在页面右侧的正常圆角外观
QTabBar::TriangularNorth 4 在页面上方的三角形选项卡。
QTabBar::TriangularSouth 5 例如,类似于 Excel 电子表格使用的那些三角形选项卡
QTabBar::TriangularWest 6 在页面左侧的三角形选项卡。
QTabBar::TriangularEast 7 在页面右侧的三角形选项卡。

特性文档编制

autoHide : bool

若为 true,自动隐藏选项卡栏,当包含少于 2 个选项卡时。

默认情况下,此特性为 false。

该特性在 Qt 5.4 引入。

访问函数:

bool autoHide () const
void setAutoHide (bool hide )

另请参阅 QWidget::visible .

changeCurrentOnDrag : bool

若为 true,当前选项卡会自动改变,当在选项卡栏拖曳时。

注意: 还应设置 acceptDrops 特性为 true 以使此特征工作。

默认情况下,此特性为 false。

该特性在 Qt 5.4 引入。

访问函数:

bool changeCurrentOnDrag () const
void setChangeCurrentOnDrag (bool change )

count : const int

此特性保持选项卡栏的选项卡数

访问函数:

int count () const

currentIndex : int

此特性保持选项卡栏的可见选项卡索引

当前索引为 -1,若没有当前选项卡。

访问函数:

int currentIndex () const
void setCurrentIndex (int index )

通知程序信号:

void currentChanged (int index )

documentMode : bool

此特性保持选项卡栏是否按适合主窗口的模式被渲染。

此特性通常用作它们在选项卡 Widget 中按不同外观方式绘制选项卡的样式提示。在 macOS,外观将类似 Safari 或 Sierra 的 Terminal.app 选项卡。

该特性在 Qt 4.5 引入。

访问函数:

bool documentMode () const
void setDocumentMode (bool set )

另请参阅 QTabWidget::documentMode .

drawBase : bool

定义选项卡栏是否应该绘制其基。

若 true 则 QTabBar 绘制样式重叠关系基。否则只绘制选项卡。

访问函数:

bool drawBase () const
void setDrawBase (bool drawTheBase )

另请参阅 QStyle::pixelMetric (), QStyle::PM_TabBarBaseOverlap ,和 QStyleOptionTabBarBase .

elideMode : Qt::TextElideMode

如何省略标签栏文本

此特性控制如何省略项,当没有足够空间展示它们 (对于给定选项卡栏尺寸) 时。

默认情况下,值从属样式。

该特性在 Qt 4.2 引入。

访问函数:

Qt::TextElideMode elideMode () const
void setElideMode ( Qt::TextElideMode )

另请参阅 QTabWidget::elideMode , usesScrollButtons ,和 QStyle::SH_TabBar_ElideMode .

expanding : bool

当展开为 true QTabBar 将展开选项卡以使用空白空间。

默认情况下,值为 true。

该特性在 Qt 4.5 引入。

访问函数:

bool expanding () const
void setExpanding (bool enabled )

另请参阅 QTabWidget::documentMode .

iconSize : QSize

此特性保持选项卡栏的图标尺寸

默认值从属样式。 iconSize 是最大尺寸;不会按比例放大较小图标。

该特性在 Qt 4.1 引入。

访问函数:

QSize iconSize () const
void setIconSize (const QSize & size )

另请参阅 QTabWidget::iconSize .

movable : bool

此特性保持用户是否可以在选项卡栏区域内,移动选项卡。

默认情况下此特性为 false ;

该特性在 Qt 4.5 引入。

访问函数:

bool isMovable () const
void setMovable (bool movable )

selectionBehaviorOnRemove : SelectionBehavior

什么选项卡应被设为当前,在 removeTab 被调用,若被移除选项卡也是当前选项卡。

默认情况下,值为 SelectRightTab .

该特性在 Qt 4.5 引入。

访问函数:

SelectionBehavior selectionBehaviorOnRemove () const
void setSelectionBehaviorOnRemove (SelectionBehavior behavior )

另请参阅 removeTab ().

shape : Shape

此特性保持选项卡栏的选项卡形状

此特性的可能值,由形状枚举描述。

访问函数:

形状 shape () const
void setShape (Shape shape )

tabsClosable : bool

此特性保持选项卡栏是否应该在每个选项卡上放置关闭按钮

当 tabsClosable 被设为 true 时,关闭按钮将出现在选项卡左侧或右侧 (从属样式)。当按钮被点击时,选项卡信号 tabCloseRequested 会被发射。

默认情况下,值为 false。

该特性在 Qt 4.5 引入。

访问函数:

bool tabsClosable () const
void setTabsClosable (bool closable )

另请参阅 setTabButton () 和 tabRemoved ().

usesScrollButtons : bool

此特性保持选项卡栏是否应使用卷动按钮,当包含多个选项卡时。

当选项卡栏选项卡太多时 (对于其大小),选项卡栏可以选择展开其大小,或添加按钮以允许卷动选项卡。

默认情况下,值从属样式。

该特性在 Qt 4.2 引入。

访问函数:

bool usesScrollButtons () const
void setUsesScrollButtons (bool useButtons )

另请参阅 elideMode , QTabWidget::usesScrollButtons ,和 QStyle::SH_TabBar_PreferNoArrows .

成员函数文档编制

QTabBar:: QTabBar ( QWidget * parent = Q_NULLPTR)

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

QTabBar:: ~QTabBar ()

销毁选项卡栏。

QString QTabBar:: accessibleTabName ( int index ) const

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

另请参阅 setAccessibleTabName ().

int QTabBar:: addTab (const QString & text )

添加新选项卡采用文本 text 。返回新选项卡的索引。

int QTabBar:: addTab (const QIcon & icon , const QString & text )

这是重载函数。

添加新选项卡采用图标 icon 和文本 text 。返回新选项卡的索引。

[virtual protected] void QTabBar:: changeEvent ( QEvent * event )

重实现自 QWidget::changeEvent ().

[signal] void QTabBar:: currentChanged ( int index )

此信号被发射当选项卡栏的当前选项卡改变时。新的当前具有给定 index ,或 -1 若没有新的 (例如:若没有选项卡在 QTabBar )

注意: 通知程序信号对于特性 currentIndex .

[virtual protected] bool QTabBar:: event ( QEvent * event )

重实现自 QObject::event ().

[virtual protected] void QTabBar:: hideEvent ( QHideEvent * )

重实现自 QWidget::hideEvent ().

[protected] void QTabBar:: initStyleOption ( QStyleOptionTab * option , int tabIndex ) const

初始化 option 采用值从选项卡在 tabIndex 。此方法对子类是有用的,当需要 QStyleOptionTab ,但不希望自己填充所有信息。

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

int QTabBar:: insertTab ( int index , const QString & text )

插入新选项卡采用文本 text 在位置 index 。若 index 超出范围,追加新选项卡。返回新选项卡的索引。

int QTabBar:: insertTab ( int index , const QIcon & icon , const QString & text )

这是重载函数。

插入新选项卡采用图标 icon 和文本 text 在位置 index 。若 index 超出范围,追加新选项卡。返回新选项卡的索引。

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

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

bool QTabBar:: isTabEnabled ( int index ) const

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

[virtual protected] void QTabBar:: keyPressEvent ( QKeyEvent * event )

重实现自 QWidget::keyPressEvent ().

[virtual] QSize QTabBar:: minimumSizeHint () const

重实现自 QWidget::minimumSizeHint ().

[virtual protected] QSize QTabBar:: minimumTabSizeHint ( int index ) const

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

该函数在 Qt 5.0 引入。

[virtual protected] void QTabBar:: mouseMoveEvent ( QMouseEvent * event )

重实现自 QWidget::mouseMoveEvent ().

[virtual protected] void QTabBar:: mousePressEvent ( QMouseEvent * event )

重实现自 QWidget::mousePressEvent ().

[virtual protected] void QTabBar:: mouseReleaseEvent ( QMouseEvent * event )

重实现自 QWidget::mouseReleaseEvent ().

void QTabBar:: moveTab ( int from , int to )

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

该函数在 Qt 4.5 引入。

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

[virtual protected] void QTabBar:: paintEvent ( QPaintEvent * )

重实现自 QWidget::paintEvent ().

void QTabBar:: removeTab ( int index )

移除选项卡,在位置 index .

另请参阅 SelectionBehavior .

[virtual protected] void QTabBar:: resizeEvent ( QResizeEvent * )

重实现自 QWidget::resizeEvent ().

void QTabBar:: setAccessibleTabName ( int index , const QString & name )

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

另请参阅 accessibleTabName ().

void QTabBar:: setTabButton ( int index , ButtonPosition position , QWidget * widget )

widget 在选项卡 index 。Widget 被放置在左侧或右侧从属 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 () 和 tabsClosable ().

void QTabBar:: setTabData ( int index , const QVariant & data )

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

另请参阅 tabData ().

void QTabBar:: setTabEnabled ( int index , bool enabled )

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

另请参阅 isTabEnabled ().

void QTabBar:: setTabIcon ( int index , const QIcon & icon )

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

另请参阅 tabIcon ().

void QTabBar:: setTabText ( int index , const QString & text )

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

另请参阅 tabText ().

void QTabBar:: setTabTextColor ( int index , const QColor & color )

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

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

另请参阅 tabTextColor ().

void QTabBar:: setTabToolTip ( int index , const QString & tip )

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

另请参阅 tabToolTip ().

void QTabBar:: setTabWhatsThis ( int index , const QString & text )

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

该函数在 Qt 4.1 引入。

另请参阅 tabWhatsThis ().

[virtual protected] void QTabBar:: showEvent ( QShowEvent * )

重实现自 QWidget::showEvent ().

[virtual] QSize QTabBar:: sizeHint () const

重实现自 QWidget::sizeHint ().

int QTabBar:: tabAt (const QPoint & position ) const

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

该函数在 Qt 4.3 引入。

[signal] void QTabBar:: tabBarClicked ( int index )

此信号会被发射,当用户点击选项卡在 index .

index 是点击选项卡索引,或 -1 若光标下没有选项卡。

该函数在 Qt 5.2 引入。

[signal] void QTabBar:: tabBarDoubleClicked ( int index )

此信号被发射当用户双击选项卡在 index .

index 引用选项卡点击,或 -1 若光标下没有选项卡。

该函数在 Qt 5.2 引入。

QWidget *QTabBar:: tabButton ( int index , ButtonPosition position ) const

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

另请参阅 setTabButton ().

[signal] void QTabBar:: tabCloseRequested ( int index )

此信号被发射当点击选项卡关闭按钮时。 index 是应被移除的索引。

该函数在 Qt 4.5 引入。

另请参阅 setTabsClosable ().

QVariant QTabBar:: tabData ( int index ) const

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

另请参阅 setTabData ().

QIcon QTabBar:: tabIcon ( int index ) const

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

另请参阅 setTabIcon ().

[virtual protected] void QTabBar:: tabInserted ( int index )

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

另请参阅 tabRemoved ().

[virtual protected] void QTabBar:: tabLayoutChange ()

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

另请参阅 tabRect ().

[signal] void QTabBar:: tabMoved ( int from , int to )

此信号被发射当选项卡已移动选项卡在索引位置 from 到索引位置 to .

注意: QTabWidget 会自动移动页面,当此信号从其选项卡栏被发射时。

该函数在 Qt 4.5 引入。

另请参阅 moveTab ().

QRect QTabBar:: tabRect ( int index ) const

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

[virtual protected] void QTabBar:: tabRemoved ( int index )

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

另请参阅 tabInserted ().

[virtual protected] QSize QTabBar:: tabSizeHint ( int index ) const

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

QString QTabBar:: tabText ( int index ) const

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

另请参阅 setTabText ().

QColor QTabBar:: tabTextColor ( int index ) const

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

另请参阅 setTabTextColor ().

QString QTabBar:: tabToolTip ( int index ) const

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

另请参阅 setTabToolTip ().

QString QTabBar:: tabWhatsThis ( int index ) const

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

该函数在 Qt 4.1 引入。

另请参阅 setTabWhatsThis ().

[virtual protected] void QTabBar:: timerEvent ( QTimerEvent * event )

重实现自 QObject::timerEvent ().

[virtual protected] void QTabBar:: wheelEvent ( QWheelEvent * event )

重实现自 QWidget::wheelEvent ().