Classes - Annotated - Tree - Functions - Home - Structure

QTabWidget Class Reference

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

#include <qtabwidget.h>

Inherits QWidget.

List of all member functions.

Public Members

Public Slots

Signals

Properties

Protected Members


Detailed Description

The QTabWidget class provides a stack of tabbed widgets.

A tabbed widget is one in which several "pages" are available and the user selects which page to see and use by clicking on its tab or by pressing the indicated Alt-letter key combination.

QTabWidget does not provide more than one row of tabs and does not provide tabs along the sides or bottom of the pages.

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() to set up a tab and keyboard accelerator for it.
  3. Connect to the signals and slots.

If you don't call addTab() the page you have created will not be visible. Please 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.

Each tab is either enabled or disabled at any given time. 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 make a royal mess out of it. 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.


Member Type Documentation

QTabWidget::TabPosition

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

QTabWidget::TabShape

This enum type defines the shape of the tabs:


Member Function Documentation

QTabWidget::QTabWidget ( QWidget * parent, const char * name, WFlags f )

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

QTabWidget::QTabWidget ( QWidget * parent = 0, const char * name = 0 )

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

Constructs a tabbed widget with parent parent called name.

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

Adds another tab and page to the tab view.

The tab will be labeled label; child constitutes the new page. 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, for example.

label is written in the QButton style, in which &P makes Qt create an accelerator key on Alt-P for this page. For example:

    td->addTab( graphicsPane, "&Graphics" );
    td->addTab( soundPane, "&Sound" );
  

If the user presses Alt-S the sound page of the tab dialog is shown; if the user presses Alt-P the graphics page is shown.

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

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

void QTabWidget::addTab ( QWidget * child, const QIconSet & iconset, const QString & 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 lower-level method for adding tabs, similar to the other addTab() 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 and tab is the tab to put the child on.

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

Defines a new label for the tab of page w.

void QTabWidget::changeTab ( QWidget * w, const QIconSet & iconset, const QString & 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 the tab of page w.

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.

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 of the current tab page. See the "currentPage" property for details.

int QTabWidget::indexOf ( QWidget * w ) const

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

void QTabWidget::insertTab ( QWidget * child, const QString & label, int index = -1 ) [virtual]

Inserts another tab and page to the tab view.

The tab will be labeled label; child constitutes the new page. 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, for example.

label is written in the QButton style, in which &P makes Qt create an accelerator key on Alt-P for this page. For example:

    td->insertTab( graphicsPane, "&Graphics" );
    td->insertTab( soundPane, "&Sound" );
  

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

If the user presses Alt-S the sound page of the tab dialog is shown; if the user presses Alt-P the graphics page is shown.

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

void QTabWidget::insertTab ( QWidget * child, const QIconSet & iconset, const QString & label, int index = -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, int index = -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 and FALSE if it is disabled.

See also setTabEnabled() and QWidget::enabled.

QString QTabWidget::label ( int index ) const

Returns the label of the tab page at index index

int QTabWidget::margin () const

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

QSize QTabWidget::minimumSizeHint () const [virtual]

Returns a suitable minimum size for the tab widget.

Reimplemented from QWidget.

QWidget * QTabWidget::page ( int index ) const

Returns the tab page at the index 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::setCurrentPage ( int ) [slot]

Sets the index 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, bool enable )

Enables/disables page w according to the value of enable and redraws the page's tab 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, const QIconSet & iconset )

Set the iconset for the page w to iconset.

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

Sets the label of the 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 ( TabShape s )

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

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

Ensures that 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 for the page w.

QString QTabWidget::tabLabel ( QWidget * w ) const

Returns the text in the tab for 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.


Property Documentation

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 of the current tab page.

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

See also QTabBar::currentPage().

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.

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.

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


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta2