Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTabWidget Class Reference
[QtGui module]

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

 #include <QTabWidget>

Inherits QWidget.

Public Types

Properties

  • 55 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

  • 195 public functions inherited from QWidget
  • 29 public functions inherited from QObject
  • 12 public functions inherited from QPaintDevice

Public Slots

  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

Protected Functions

  • 38 protected functions inherited from QWidget
  • 7 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Additional Inherited Members

  • 4 static public members inherited from QWidget
  • 5 static public members inherited from QObject
  • 1 protected slot inherited from QWidget

Detailed Description

The QTabWidget class provides a stack of tabbed widgets.

A tab widget provides a tab bar (see QTabBar) and a "page area" that is used to display pages related to each tab. By default, the tab bar is shown above the page area, but different configurations are available (see TabPosition). Each tab is associated with a different widget (called a page). Only the current page is shown in the page area; all the other pages are hidden. The user can show a different page by clicking on its tab or by pressing its Alt+letter shortcut if it has one.

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

  1. Create a QTabWidget.
  2. Create a QWidget for each of the pages in the tab dialog, but do not specify a parent widget - the tab widget will reparent the page widget later.
  3. Insert children into the page widget, set up geometry management for it and use addTab() (or insertTab()) to set up a tab with an optional keyboard shortcut.
  4. Connect to the signals and slots.

The position of the tabs is defined by tabPosition, their shape by tabShape.

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

The current page index is available as currentIndex(), the current page widget with currentWidget(). You can retrieve a pointer to a page widget with a given index using widget(), and can find the index position of a widget with indexOf(). Use setCurrentWidget() or setCurrentIndex() to show a particular page.

You can change a tab's text and icon using setTabText() or setTabIcon(). A tab can be removed with removeTab().

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

Tab widgets can be a very good way to split up a complex dialog. An alternative is to use a QStackedWidget for which you provide some means of navigating between pages, for example, a QToolBar or a QListWidget.

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

Screenshot of a Windows XP style tab widgetScreenshot of a Macintosh style tab widgetScreenshot of a Plastique style tab widget
A Windows XP style tab widget.A Macintosh style tab widget.A Plastique style tab widget.

See also QTabBar, QStackedWidget, QToolBox, and Tab Dialog Example.


Member Type Documentation

enum QTabWidget::TabPosition

This enum type defines where QTabWidget draws the tab row:

ConstantValueDescription
QTabWidget::North0The tabs are drawn above the pages.
QTabWidget::South1The tabs are drawn below the pages.
QTabWidget::West2The tabs are drawn to the left of the pages.
QTabWidget::East3The tabs are drawn to the right of the pages.

enum QTabWidget::TabShape

This enum type defines the shape of the tabs:

ConstantValueDescription
QTabWidget::Rounded0rounded look (normal)
QTabWidget::Triangular1triangular look


Property Documentation

count : const int

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

Access functions:

  • int count () const

currentIndex : int

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

Access functions:

  • int currentIndex () const
  • void setCurrentIndex ( int index )

elideMode : Qt::TextElideMode

This property holds how to elide text in the tab bar.

This property controls how items are elided when there is not enough space to show them for a given tab bar size.

By default the value is style dependant.

This property was introduced in Qt 4.2.

Access functions:

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

See also QTabBar::elideMode, usesScrollButtons, and QStyle::SH_TabBar_ElideMode.

iconSize : QSize

This property holds the size for icons in the tab bar.

The default value is style-dependent.

This property was introduced in Qt 4.2.

Access functions:

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

See also QTabBar::iconSize.

tabPosition : TabPosition

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

Possible values for this property are described by the TabPosition enum.

Access functions:

  • TabPosition tabPosition () const
  • void setTabPosition ( TabPosition )

See also 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.

Access functions:

  • TabShape tabShape () const
  • void setTabShape ( TabShape s )

See also TabShape.

usesScrollButtons : bool

This property holds whether or not a tab bar should use buttons to scroll tabs when it has many tabs.

When there are too many tabs in a tab bar for its size, the tab bar can either choose to expand it's size or to add buttons that allow you to scroll through the tabs.

By default the value is style dependant.

This property was introduced in Qt 4.2.

Access functions:

  • bool usesScrollButtons () const
  • void setUsesScrollButtons ( bool useButtons )

See also elideMode, QTabBar::usesScrollButtons, and QStyle::SH_TabBar_PreferNoArrows.


Member Function Documentation

QTabWidget::QTabWidget ( QWidget * parent = 0 )

Constructs a tabbed widget with parent parent.

QTabWidget::~QTabWidget ()

Destroys the tabbed widget.

int QTabWidget::addTab ( QWidget * child, const QString & label )

Adds another tab and page to the tab view.

The new page is child; the tab's label is label.

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

If you call addTab() after show(), the layout system will try to adjust to the changes in it's widgets hierarchy and may cause flicker. To prevent this, you can set the QWidget::updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

See also insertTab().

int QTabWidget::addTab ( QWidget * child, const QIcon & icon, const QString & label )

This is an overloaded member function, provided for convenience.

Adds another tab and page to the tab view.

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

QWidget * QTabWidget::cornerWidget ( Qt::Corner corner = Qt::TopRightCorner ) const

Returns the widget shown in the corner of the tab widget or 0.

See also setCornerWidget().

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

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

See also currentWidget() and currentIndex.

QWidget * QTabWidget::currentWidget () 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).

See also currentIndex() and setCurrentWidget().

int QTabWidget::indexOf ( QWidget * w ) const

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

int QTabWidget::insertTab ( int index, QWidget * widget, const QString & label )

Inserts another tab and page to the tab view.

The given widget is the new page, and the tab's label is specified by label. Note the difference between the widget name 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 a shortcut for the tab, e.g. if the label is "Bro&wse" then Alt+W becomes a shortcut which will move the focus to this tab.

If index is out of range, the tab is simply appended. Otherwise it is inserted at the specified position.

If the QTabWidget was empty before this function is called, the new page becomes the current page. Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current page.

If you call insertTab() after show(), the layout system will try to adjust to the changes in it's widgets hierarchy and may cause flicker. To prevent this, you can set the QWidget::updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

See also addTab().

int QTabWidget::insertTab ( int index, QWidget * widget, const QIcon & icon, const QString & label )

This is an overloaded member function, provided for convenience.

Inserts another tab and page to the tab view.

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

bool QTabWidget::isTabEnabled ( int index ) const

Returns true if the the page at position index is enabled; otherwise returns false.

See also setTabEnabled() and QWidget::isEnabled().

void QTabWidget::paintEvent ( QPaintEvent * event )   [virtual protected]

Paints the tab widget's tab bar in response to the paint event.

Reimplemented from QWidget.

void QTabWidget::removeTab ( int index )

Removes the page at position index from this stack of widgets. Does not delete the page widget.

void QTabWidget::setCornerWidget ( QWidget * widget, Qt::Corner corner = Qt::TopRightCorner )

Sets the given widget to be shown in the specified corner of the tab widget.

Only the horizontal element of the corner will be used.

Note: Corner widgets are designed for North and South tab positions; other orientations are known to not work properly.

See also cornerWidget() and setTabPosition().

void QTabWidget::setCurrentWidget ( QWidget * widget )   [slot]

Makes widget the current widget. The widget used must be a page in this tab widget.

See also addTab(), setCurrentIndex(), and currentWidget().

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

Replaces the dialog's QTabBar heading with 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 ( int index, bool enable )

If enable is true, the page at position index is enabled; otherwise the page at position index 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::setEnabled().

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

Sets the icon for the tab at position index.

See also tabIcon().

void QTabWidget::setTabText ( int index, const QString & label )

Defines a new label for the page at position index's tab.

If the provided text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See the QShortcut documentation for details (to display an actual ampersand, use '&&').

See also tabText().

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

Sets the tab tool tip for the page at position index to tip.

See also tabToolTip().

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

Sets the What's This help text for the page at position index to text.

This function was introduced in Qt 4.1.

See also tabWhatsThis().

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

Returns the current QTabBar.

See also setTabBar().

QIcon QTabWidget::tabIcon ( int index ) const

Returns the label text for the tab on the page at position index.

See also setTabIcon().

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

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

See also tabRemoved().

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

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

See also tabInserted().

QString QTabWidget::tabText ( int index ) const

Returns the label text for the tab on the page at position index.

See also setTabText().

QString QTabWidget::tabToolTip ( int index ) const

Returns the tab tool tip for the page at position index or an empty string if no tool tip has been set.

See also setTabToolTip().

QString QTabWidget::tabWhatsThis ( int index ) const

Returns the What's This help text for the page at position index, or an empty string if no help text has been set.

This function was introduced in Qt 4.1.

See also setTabWhatsThis().

QWidget * QTabWidget::widget ( int index ) const

Returns the tab page at index position index or 0 if the index is out of range.


Member Function Documentation

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

Use one of the constructors that doesn't take the name argument and then use setObjectName() instead.

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

Use setTabText() instead.

void QTabWidget::changeTab ( QWidget * widget, const QIcon & icon, const QString & label )

This is an overloaded member function, provided for convenience.

Use setTabText() and setTabIcon() instead.

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

This is an overloaded member function, provided for convenience.

Use currentChanged(int) instead.

QWidget * QTabWidget::currentPage () const

Use currentWidget() instead.

See also setCurrentPage().

int QTabWidget::currentPageIndex () const

Use currentIndex() instead.

void QTabWidget::insertTab ( QWidget * widget, const QString & label, int index = -1 )

This is an overloaded member function, provided for convenience.

Use insertTab(index, widget, label) instead.

void QTabWidget::insertTab ( QWidget * widget, const QIcon & icon, const QString & label, int index = -1 )

This is an overloaded member function, provided for convenience.

Use insertTab(index, widget, icon, label) instead.

bool QTabWidget::isTabEnabled ( QWidget * widget ) const

This is an overloaded member function, provided for convenience.

Use isTabEnabled(tabWidget->indexOf(widget)) instead.

QString QTabWidget::label ( int index ) const

Use tabText() instead.

int QTabWidget::margin () const

This function is kept only to make old code compile. This functionality is no longer supported by QTabWidget.

See also setMargin(), contentsRect(), and setContentsMargins().

QWidget * QTabWidget::page ( int index ) const

Use widget() instead.

void QTabWidget::removePage ( QWidget * widget )   [slot]

Use removeTab(indexOf(widget)) instead.

void QTabWidget::removeTabToolTip ( QWidget * widget )

Use setTabToolTip(tabWidget->indexOf(widget), QString()) instead.

void QTabWidget::selected ( const QString & tabLabel )   [signal]

This signal is emitted whenever a tab is selected (raised), including during the first show().

You can normally use currentChanged() instead.

void QTabWidget::setCurrentPage ( int index )   [slot]

Use setCurrentIndex() instead.

See also currentPage().

void QTabWidget::setMargin ( int margin )

This function is kept only to make old code compile. This functionality is no longer supported by QTabWidget.

See also margin(), contentsRect(), and setContentsMargins().

void QTabWidget::setTabEnabled ( QWidget * widget, bool b )

This is an overloaded member function, provided for convenience.

Use isTabEnabled(tabWidget->indexOf(widget), b) instead.

void QTabWidget::setTabIconSet ( QWidget * widget, const QIcon & icon )

Use setTabIcon(tabWidget->indexOf(widget), icon) instead.

See also tabIconSet().

void QTabWidget::setTabLabel ( QWidget * widget, const QString & label )

Use setTabText(tabWidget->indexOf(widget), label) instead.

See also tabLabel().

void QTabWidget::setTabToolTip ( QWidget * widget, const QString & tip )

This is an overloaded member function, provided for convenience.

Use setTabToolTip(tabWidget->indexOf(widget), tip) instead.

void QTabWidget::showPage ( QWidget * widget )   [slot]

Use setCurrentIndex(indexOf(widget)) instead.

QIcon QTabWidget::tabIconSet ( QWidget * widget ) const

Use tabIcon(tabWidget->indexOf(widget)) instead.

See also setTabIconSet().

QString QTabWidget::tabLabel ( QWidget * widget ) const

Use tabText(tabWidget->indexOf(widget)) instead.

See also setTabLabel().

QString QTabWidget::tabToolTip ( QWidget * widget ) const

This is an overloaded member function, provided for convenience.

Use tabToolTip(tabWidget->indexOf(widget)) instead.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 64
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le Qt Developer Network au hasard

Logo

Comment fermer une application

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.2
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web