QTabBar Class Reference
|
|
|
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.
A tab bar shown in the Plastique widget style. | |
A truncated tab bar shown in the Plastique widget style. |
See also QTabWidget.
This enum type lists the built-in shapes supported by QTabBar. Treat these as hints as some styles may not render some of the shapes. However, position should be honored.
Constant | Value | Description |
---|---|---|
QTabBar::RoundedNorth | 0 | The normal rounded look above the pages |
QTabBar::RoundedSouth | 1 | The normal rounded look below the pages |
QTabBar::RoundedWest | 2 | The normal rounded look on the left side of the pages |
QTabBar::RoundedEast | 3 | The normal rounded look on the right side the pages |
QTabBar::TriangularNorth | 4 | Triangular tabs above the pages. |
QTabBar::TriangularSouth | 5 | Triangular tabs similar to those used in the Excel spreadsheet, for example |
QTabBar::TriangularWest | 6 | Triangular tabs on the left of the pages. |
QTabBar::TriangularEast | 7 | Triangular tabs on the right of the pages. |
This property holds the number of tabs in the tab bar.
Access functions:
This property holds the index of the tab bar's visible tab.
The current index is -1 if there is no current tab.
Access functions:
This property defines whether or not tab bar should draw its base.
If true then QTabBar draws a base in relation to the styles overlab. Otherwise only the tabs are drawn.
Access functions:
See also QStyle::pixelMetric(), QStyle::PM_TabBarBaseOverlap, and QStyleOptionTabBarBase.
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 dependent.
This property was introduced in Qt 4.2.
Access functions:
See also QTabWidget::elideMode, usesScrollButtons, and QStyle::SH_TabBar_ElideMode.
This property holds the size for icons in the tab bar.
The default value is style-dependent. iconSize is a maximum size; icons that are smaller are not scaled up.
This property was introduced in Qt 4.1.
Access functions:
See also QTabWidget::iconSize.
This property holds the shape of the tabs in the tab bar.
Possible values for this property are described by the Shape enum.
Access functions:
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 its 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:
See also elideMode, QTabWidget::usesScrollButtons, and QStyle::SH_TabBar_PreferNoArrows.
Creates a new tab bar with the given parent.
Destroys the tab bar.
Adds a new tab with text text. Returns the new tab's index.
This is an overloaded member function, provided for convenience.
Adds a new tab with icon icon and text text. Returns the new tab's index.
This signal is emitted when the tab bar's current tab changes. The new current has the given index, or -1 if there isn't a new one (for example, if there are no tab in the QTabBar)
Initialize option with the values from the tab at tabIndex. This method is useful for subclasses when they need a QStyleOptionTab or QStyleOptionTabV2, but don't want to fill in all the information themselves. This function will check the version of the QStyleOptionTab and fill in the additional values for a QStyleOptionTabV2.
See also QStyleOption::initFrom() and QTabWidget::initStyleOption().
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.
This is an overloaded member function, provided for convenience.
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.
If the QTabBar was empty before this function is called, the inserted tab becomes the current tab.
Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current tab.
Returns true if the tab at position index is enabled; otherwise returns false.
Removes the tab at position index.
Sets the data of the tab at position index to data.
See also tabData().
If enabled is true then the tab at position index is enabled; otherwise the item at position index is disabled.
See also isTabEnabled().
Sets the icon of the tab at position index to icon.
See also tabIcon().
Sets the text of the tab at position index to text.
See also tabText().
Sets the color of the text in the tab with the given index to the specified color.
If an invalid color is specified, the tab will use the QTabBar foreground role instead.
See also tabTextColor().
Sets the tool tip of the tab at position index to tip.
See also tabToolTip().
Sets the What's This help text of the tab at position index to text.
This function was introduced in Qt 4.1.
See also tabWhatsThis().
Returns the index of the tab that covers position or -1 if no tab covers position;
This function was introduced in Qt 4.3.
Returns the datad of the tab at position index, or a null variant if index is out of range.
See also setTabData().
Returns the icon of the tab at position index, or a null icon if index is out of range.
See also setTabIcon().
This virtual handler is called after a new tab was added or inserted at position index.
See also tabRemoved().
This virtual handler is called whenever the tab layout changes.
See also tabRect().
Returns the visual rectangle of the of the tab at position index, or a null rectangle if index is out of range.
This virtual handler is called after a tab was removed from position index.
See also tabInserted().
Returns the size hint for the tab at position index.
Returns the text of the tab at position index, or an empty string if index is out of range.
See also setTabText().
Returns the text color of the tab with the given index, or a invalid color if index is out of range.
See also setTabTextColor().
Returns the tool tip of the tab at position index, or an empty string if index is out of range.
See also setTabToolTip().
Returns the What's This help text of the tab at position index, or an empty string if index is out of range.
This function was introduced in Qt 4.1.
See also setTabWhatsThis().
Copyright © 2008 Nokia | Trademarks | Qt 4.4.3 |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |