Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTabBar Class Reference

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

    #include <QTabBar>

Inherits QWidget.

- List of all members, including inherited members
- Compatibility members

### Public Types

- enum Shape { RoundedAbove, RoundedBelow, TriangularAbove, TriangularBelow }

### Writable Properties

- currentIndex : int
- shape : Shape

- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- count : int

- 24 read-only properties inherited from QWidget

### Public Functions

- QTabBar ( QWidget * parent = 0 )
- ~QTabBar ()
- int addTab ( const QString & text )
- int addTab ( const QIcon & icon, const QString & text )
- int insertTab ( int index, const QString & text )
- int insertTab ( int index, const QIcon & icon, const QString & text )
- bool isTabEnabled ( int index ) const
- void removeTab ( int index )
- void setTabEnabled ( int index, bool enabled )
- void setTabIcon ( int index, const QIcon & icon )
- void setTabText ( int index, const QString & text )
- void setTabToolTip ( int index, const QString & tip )
- QIcon tabIcon ( int index ) const
- QRect tabRect ( int index ) const
- QString tabText ( int index ) const
- QString tabToolTip ( int index ) const

- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- void setCurrentIndex ( int index )

- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void currentChanged ( int index )

- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual void tabInserted ( int index )
- virtual void tabLayoutChange ()
- virtual void tabRemoved ( int index )
- virtual QSize tabSizeHint ( int index ) const

- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## 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(), and an optional tabToolTip(). The tabs's attributes can be changed with setTabText(), setTabIcon(), and setTabToolTip(). Each tabs can be enabled or disabled individually with setTabEnabled().

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 `RoundedAbove`; nobody uses `TriangularAbove`. Tab controls in windows other than dialogs almost always use either `RoundedBelow` or `TriangularBelow`. Many spreadsheets and other tab controls in which all the pages are essentially similar use `TriangularBelow`, whereas `RoundedBelow` is used mostly when the pages are different (e.g. a multi-page tool palette). The default in QTabBar is `RoundedAbove`.

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 QButton; 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:

- tabSizeHint() calcuates the size of a tab.
- tabInserted() notifies that a new tab was added.
- tabRemoved() notifies that a tab was removed.
- tabLayoutChange() notifies that the tabs have been re-laid out.
- paintEvent() paints all tabs.

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

## Member Type Documentation

### enum QTabBar::Shape

This enum type lists the built-in shapes supported by QTabBar:

`QTabBar::RoundedAbove` | the normal rounded look above the pages
`QTabBar::RoundedBelow` | the normal rounded look below the pages
`QTabBar::TriangularAbove` | triangular tabs above the pages (very unusual; included for completeness)
`QTabBar::TriangularBelow` | triangular tabs similar to those used in the Excel spreadsheet, for example

## Property Documentation

### count : int

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

Access functions:

- int count () const

### currentIndex : int

This property holds the index of the tab bar's visible tab.

Access functions:

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

### shape : Shape

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

The value of this property is one of the following: `RoundedAbove` (default), `RoundedBelow`, `TriangularAbove` or `TriangularBelow`.

Access functions:

- Shape shape () const
- void setShape ( Shape shape )

See also Shape.

## Member Function Documentation

### QTabBar::QTabBar ( QWidget * parent = 0 )

Creates a new tab bar with the given parent.

### QTabBar::~QTabBar ()

Destroys the tab bar.

### int QTabBar::addTab ( const QString & text )

Adds a new tab with text text. Returns the new tab's index.

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

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

Adds a new tab with icon icon and text text. Returns the new tab's index.

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

This signal is emitted when the tab bar's current tab changes. The new current has the given index.

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

Inserts a new tab with text text at position index. If index is out of range, the new tab is appened. Returns the new tab's index.

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

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

Inserts a new tab with icon icon and text text at position index. If index is out of range, the new tab is appended. Returns the new tab's index.

### bool QTabBar::isTabEnabled ( int index ) const

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

### void QTabBar::removeTab ( int index )

Removes the tab at position index.

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

If enabled is true then the tab at position index is enabled; otherwise the item at position index is disabled.

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

Sets the icon of the tab at position index to icon.

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

Sets the text of the tab at position index to text.

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

Sets the tool tip of the tab at position index to tip.

### QIcon QTabBar::tabIcon ( int index ) const

Returns the icon of the tab at position index, or a null icon if index is out of range.

### void QTabBar::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 QTabBar::tabLayoutChange () `[virtual protected]`

This virtual handler is called whenever the tab layout changes.

See also tabRect().

### QRect QTabBar::tabRect ( int index ) const

Returns the visual rectangle of the of the tab at position index, or a null rectangle if index is out of range.

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

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

See also tabInserted().

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

Returns the size hint for the tab at position index.

### QString QTabBar::tabText ( int index ) const

Returns the text of the tab at position index, or an empty string if index is out of range.

### QString QTabBar::tabToolTip ( int index ) const

Returns the tool tip of the tab at position index, or an empty string if index is out of range.