Home · Overviews · Examples 

QTabBar Class Reference
[com.trolltech.qt.gui module]

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

Inherits QWidget.


Detailed Description

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, and 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.

Each tab has a tabText, an optional tabIcon, an optional tabToolTip, optional tabWhatsThis and optional 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.

Tabs are added using 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 and insertTab allows you to move tabs to different positions.

The 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:

For subclasses, you might also need the tabRect functions which returns the visual geometry of a single tab.

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

See also QTabWidget.


Copyright © 2007 Trolltech Trademarks
Qt Jambi 4.3.2_01