返回介绍

QTabWidget Class

发布于 2019-10-04 15:03:14 字数 17498 浏览 931 评论 0 收藏 0

The QTabWidget class provides a stack of tabbed widgets. More...

#include <qtabwidget.h>

Inherits QWidget.

List of all member functions.

Public Members

  • QTabWidget ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )
  • virtual void addTab ( QWidget*child, constQString&label )
  • virtual void addTab ( QWidget*child, constQIconSet&iconset, constQString&label )
  • virtual void addTab ( QWidget*child, QTab*tab )
  • virtual void insertTab ( QWidget*child, constQString&label, intindex = -1 )
  • virtual void insertTab ( QWidget*child, constQIconSet&iconset, constQString&label, intindex = -1 )
  • virtual void insertTab ( QWidget*child, QTab*tab, intindex = -1 )
  • void changeTab ( QWidget*w, constQString&label )
  • void changeTab ( QWidget*w, constQIconSet&iconset, constQString&label )
  • bool isTabEnabled ( QWidget*w ) const
  • void setTabEnabled ( QWidget*w, boolenable )
  • QString tabLabel ( QWidget*w ) const
  • void setTabLabel ( QWidget*w, constQString&l )
  • QIconSet tabIconSet ( QWidget*w ) const
  • void setTabIconSet ( QWidget*w, constQIconSet&iconset )
  • void removeTabToolTip ( QWidget*w )
  • void setTabToolTip ( QWidget*w, constQString&tip )
  • QString tabToolTip ( QWidget*w ) const
  • QWidget * currentPage () const
  • QWidget * page ( intindex ) const
  • QString label ( intindex ) const
  • int currentPageIndex () const
  • int indexOf ( QWidget*w ) const
  • enum TabPosition { Top, Bottom }
  • TabPosition tabPosition () const
  • void setTabPosition ( TabPosition )
  • enum TabShape { Rounded, Triangular }
  • TabShape tabShape () const
  • void setTabShape ( TabShapes )
  • int margin () const
  • void setMargin ( int )
  • int count () const

Public Slots

  • void setCurrentPage ( int )
  • virtual void showPage ( QWidget*w )
  • virtual void removePage ( QWidget*w )

Signals

  • void currentChanged ( QWidget * )

Properties

  • bool autoMask- whether the tab widget is automatically masked (read only)
  • int count- the number of tabs in the tab bar (read only)
  • int currentPage- the index position of the current tab page
  • int margin- the margin in this tab widget
  • TabPosition tabPosition- the position of the tabs in this tab widget
  • TabShape tabShape- the shape of the tabs in this tab widget

Protected Members

  • void setTabBar ( QTabBar*tb )
  • QTabBar * tabBar () const

Detailed Description

The QTabWidget class provides a stack of tabbed widgets.

A tabbed widget is a widget that has a tab bar of tabs, and for each tab a "page" which is a widget. The user selects which page to see and use by clicking on its tab or by pressing the indicated Alt+letter key combination.

QTabWidget provides a single row of tabs along the top or bottom of the pages (see TabPosition).

The normal way to use QTabWidget is to do the following in the constructor:

  1. Create a QTabWidget.
  2. Create a QWidget for each of the pages in the tab dialog, insert children into it, set up geometry management for it and use addTab() (or insertTab()) to set up a tab and keyboard accelerator for it.
  3. Connect to the signals and slots.

The position of the tabs is set with setTabPosition(), their shape with setTabShape(), and their margin with setMargin().

If you don't call addTab() the page you have created will not be visible. Don't confuse the object name you supply to the QWidget constructor and the tab label you supply to addTab(). addTab() takes a name which indicates an accelerator and is meaningful and descriptive to the user, whereas the widget name is used primarily for debugging.

The signal currentChanged() is emitted when the user selects a page.

The current page is available as an index position with currentPageIndex() or as a wiget pointer with currentPage(). You can retrieve a pointer to a page with a given index using page(), and can find the index position of a page with indexOf(). Use setCurrentPage() to show a particular page by index, or showPage() to show a page by widget pointer.

You can change a tab's label and iconset using changeTab() or setTabLabel() and setTabIconSet(). A tab page can be removed with removePage().

Each tab is either enabled or disabled at any given time (see setTabEnabled()). If a tab is enabled, the tab text is drawn in black 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.

Although tab widgets can be a very good way to split up a complex dialog, it's also very easy to get into a mess. See QTabDialog for some design hints.

Most of the functionality in QTabWidget is provided by a QTabBar (at the top, providing the tabs) and a QWidgetStack (most of the area, organizing the individual pages).

See also QTabDialog, Advanced Widgets and Organizers.


Member Type Documentation

QTabWidget::TabPosition

This enum type defines where QTabWidget can draw the tab row:

  • QTabWidget::Top - above the pages
  • QTabWidget::Bottom - below the pages

QTabWidget::TabShape

This enum type defines the shape of the tabs:

  • QTabWidget::Rounded - rounded look (normal)
  • QTabWidget::Triangular - triangular look (very unusual, included for completeness)

Member Function Documentation

QTabWidget::QTabWidget ( QWidget*parent = 0, constchar*name = 0, WFlagsf = 0 )

Constructs a tabbed widget with parent parent, name name, and widget flags f.

void QTabWidget::addTab ( QWidget*child, constQString&label ) [virtual]

Adds another tab and page to the tab view.

The new page is child; the tab's label is label. Note the difference between the widget name (which you supply to widget constructors and to setTabEnabled(), for example) and the tab label. The name is internal to the program and invariant, whereas the label is shown on-screen and may vary according to language and other factors.

If the tab's label contains an ampersand, the letter following the ampersand is used as an accelerator for the tab, e.g. if the label is "Bro&wse" then Alt+W becomes an accelerator which will move the focus to this tab.

If you call addTab() after show() the screen will flicker and the user may be confused.

See also insertTab().

Examples: addressbook/centralwidget.cpp and themes/themes.cpp.

void QTabWidget::addTab ( QWidget*child, constQIconSet&iconset, constQString&label ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Adds another tab and page to the tab view.

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

void QTabWidget::addTab ( QWidget*child, QTab*tab ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This is a low-level function for adding tabs. It is useful if you are using setTabBar() to set a QTabBar subclass with an overridden QTabBar::paint() routine for a subclass of QTab. The child is the new page and tab is the tab to put the child on.

void QTabWidget::changeTab ( QWidget*w, constQString&label )

Defines a new label for page w's tab.

void QTabWidget::changeTab ( QWidget*w, constQIconSet&iconset, constQString&label )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Defines a new iconset and a new label for page w's tab.

int QTabWidget::count () const

Returns the number of tabs in the tab bar. See the "count" property for details.

void QTabWidget::currentChanged ( QWidget* ) [signal]

This signal is emitted whenever the current page changes. The parameter is the new current page.

See also currentPage(), showPage() and tabLabel().

QWidget* QTabWidget::currentPage () const

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).

int QTabWidget::currentPageIndex () const

Returns the index position of the current tab page. See the "currentPage" property for details.

int QTabWidget::indexOf ( QWidget*w ) const

Returns the index position of page w, or -1 if the widget cannot be found.

void QTabWidget::insertTab ( QWidget*child, constQString&label, intindex = -1 ) [virtual]

Inserts another tab and page to the tab view.

The new page is child; the tab's label is label. Note the difference between the widget name (which you supply to widget constructors and to setTabEnabled(), for example) and the tab label. The name is internal to the program and invariant, whereas the label is shown on-screen and may vary according to language and other factors.

If the tab's label contains an ampersand, the letter following the ampersand is used as an accelerator for the tab, e.g. if the label is "Bro&wse" then Alt+W becomes an accelerator which will move the focus to this tab.

If index is not specified, the tab is simply added. Otherwise it is inserted at the specified position.

If you call insertTab() after show(), the screen will flicker and the user may be confused.

See also addTab().

void QTabWidget::insertTab ( QWidget*child, constQIconSet&iconset, constQString&label, intindex = -1 ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts another tab and page to the tab view.

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

void QTabWidget::insertTab ( QWidget*child, QTab*tab, intindex = -1 ) [virtual]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This is a lower-level method for inserting tabs, similar to the other insertTab() method. It is useful if you are using setTabBar() to set a QTabBar subclass with an overridden QTabBar::paint() routine for a subclass of QTab. The child is the new page, tab is the tab to put the child on and index is the position in the tab bar that this page should occupy.

bool QTabWidget::isTabEnabled ( QWidget*w ) const

Returns TRUE if the page w is enabled; otherwise returns FALSE.

See also setTabEnabled() and QWidget::enabled.

QString QTabWidget::label ( intindex ) const

Returns the label of the tab at index position index.

int QTabWidget::margin () const

Returns the margin in this tab widget. See the "margin" property for details.

QWidget* QTabWidget::page ( intindex ) const

Returns the tab page at index position index.

void QTabWidget::removePage ( QWidget*w ) [virtual slot]

Removes page w from this stack of widgets. Does not delete w.

See also showPage() and QWidgetStack::removeWidget().

void QTabWidget::removeTabToolTip ( QWidget*w )

Removes the tab tool tip for page w. If the page does not have a tip, nothing happens.

See also setTabToolTip() and tabToolTip().

void QTabWidget::setCurrentPage ( int ) [slot]

Sets the index position of the current tab page. See the "currentPage" property for details.

void QTabWidget::setMargin ( int )

Sets the margin in this tab widget. See the "margin" property for details.

void QTabWidget::setTabBar ( QTabBar*tb ) [protected]

Replaces the QTabBar heading the dialog by the tab bar tb. Note that this must be called before any tabs have been added, or the behavior is undefined.

See also tabBar().

void QTabWidget::setTabEnabled ( QWidget*w, boolenable )

If enable is TRUE, page w is enabled; otherwise page w is disabled. The page's tab is redrawn appropriately.

QTabWidget uses QWidget::setEnabled() internally, rather than keeping a separate flag.

Note that even a disabled tab/page may be visible. If the page is visible already, QTabWidget will not hide it; if all the pages are disabled, QTabWidget will show one of them.

See also isTabEnabled() and QWidget::enabled.

void QTabWidget::setTabIconSet ( QWidget*w, constQIconSet&iconset )

Sets the iconset for page w to iconset.

void QTabWidget::setTabLabel ( QWidget*w, constQString&l )

Sets the tab label for page w to l

void QTabWidget::setTabPosition ( TabPosition )

Sets the position of the tabs in this tab widget. See the "tabPosition" property for details.

void QTabWidget::setTabShape ( TabShapes )

Sets the shape of the tabs in this tab widget to s. See the "tabShape" property for details.

void QTabWidget::setTabToolTip ( QWidget*w, constQString&tip )

Sets the tab tool tip for page w to tip.

See also removeTabToolTip() and tabToolTip().

void QTabWidget::showPage ( QWidget*w ) [virtual slot]

Ensures that page w is shown. This is useful mainly for accelerators.

Warning: Used carelessly, this function can easily surprise or confuse the user.

See also QTabBar::currentTab.

QTabBar* QTabWidget::tabBar () const [protected]

Returns the currently set QTabBar.

See also setTabBar().

QIconSet QTabWidget::tabIconSet ( QWidget*w ) const

Returns the iconset of page w.

QString QTabWidget::tabLabel ( QWidget*w ) const

Returns the label text for the tab on page w.

TabPosition QTabWidget::tabPosition () const

Returns the position of the tabs in this tab widget. See the "tabPosition" property for details.

TabShape QTabWidget::tabShape () const

Returns the shape of the tabs in this tab widget. See the "tabShape" property for details.

QString QTabWidget::tabToolTip ( QWidget*w ) const

Returns the tab tool tip for page w.

See also setTabToolTip() and removeTabToolTip().


Property Documentation

bool autoMask

This property holds whether the tab widget is automatically masked.

See also QWidget::autoMask.

int count

This property holds the number of tabs in the tab bar.

Get this property's value with count().

int currentPage

This property holds the index position of the current tab page.

Set this property's value with setCurrentPage() and get this property's value with currentPageIndex().

See also QTabBar::currentTab.

int margin

This property holds the margin in this tab widget.

The margin is the distance between the innermost pixel of the frame and the outermost pixel of the pages.

Set this property's value with setMargin() and get this property's value with margin().

TabPosition tabPosition

This property holds the position of the tabs in this tab widget.

Possible values for this property are QTabWidget::Top and QTabWidget::Bottom.

See also TabPosition.

Set this property's value with setTabPosition() and get this property's value with tabPosition().

TabShape tabShape

This property holds the shape of the tabs in this tab widget.

Possible values for this property are QTabWidget::Rounded (default) or QTabWidget::Triangular.

See also TabShape.

Set this property's value with setTabShape() and get this property's value with tabShape().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文