QtBase
v6.3.1
|
The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs. More...
#include <qtabbar.h>
Public Types | |
enum | Shape { RoundedNorth , RoundedSouth , RoundedWest , RoundedEast , TriangularNorth , TriangularSouth , TriangularWest , TriangularEast } |
enum | ButtonPosition { LeftSide , RightSide } |
enum | SelectionBehavior { SelectLeftTab , SelectRightTab , SelectPreviousTab } |
Public Types inherited from QWidget | |
enum | RenderFlag { DrawWindowBackground = 0x1 , DrawChildren = 0x2 , IgnoreMask = 0x4 } |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric { PdmWidth = 1 , PdmHeight , PdmWidthMM , PdmHeightMM , PdmNumColors , PdmDepth , PdmDpiX , PdmDpiY , PdmPhysicalDpiX , PdmPhysicalDpiY , PdmDevicePixelRatio , PdmDevicePixelRatioScaled } |
Public Slots | |
void | setCurrentIndex (int index) |
Public Slots inherited from QWidget | |
void | setEnabled (bool) |
void | setDisabled (bool) |
void | setWindowModified (bool) |
void | setWindowTitle (const QString &) |
void | setStyleSheet (const QString &styleSheet) |
void | setFocus () |
void | update () |
void | repaint () |
virtual void | setVisible (bool visible) |
void | setHidden (bool hidden) |
void | show () |
void | hide () |
void | showMinimized () |
void | showMaximized () |
void | showFullScreen () |
void | showNormal () |
bool | close () |
void | raise () |
void | lower () |
Public Slots inherited from QObject | |
void | deleteLater () |
Signals | |
void | currentChanged (int index) |
void | tabCloseRequested (int index) |
void | tabMoved (int from, int to) |
void | tabBarClicked (int index) |
void | tabBarDoubleClicked (int index) |
Signals inherited from QWidget | |
void | windowTitleChanged (const QString &title) |
void | windowIconChanged (const QIcon &icon) |
void | windowIconTextChanged (const QString &iconText) |
void | customContextMenuRequested (const QPoint &pos) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Properties | |
Shape | shape |
the shape of the tabs in the tab bar More... | |
int | currentIndex |
the index of the tab bar's visible tab More... | |
int | count |
the number of tabs in the tab bar More... | |
bool | drawBase |
defines whether or not tab bar should draw its base. More... | |
QSize | iconSize |
The size for icons in the tab bar. More... | |
Qt::TextElideMode | elideMode |
how to elide text in the tab bar More... | |
bool | usesScrollButtons |
Whether or not a tab bar should use buttons to scroll tabs when it has many tabs. More... | |
bool | tabsClosable |
Whether or not a tab bar should place close buttons on each tab. More... | |
SelectionBehavior | selectionBehaviorOnRemove |
What tab should be set as current when removeTab is called if the removed tab is also the current tab. More... | |
bool | expanding |
When expanding is true QTabBar will expand the tabs to use the empty space. More... | |
bool | movable |
This property holds whether the user can move the tabs within the tabbar area. More... | |
bool | documentMode |
Whether or not the tab bar is rendered in a mode suitable for the main window. More... | |
bool | autoHide |
If true, the tab bar is automatically hidden when it contains less than 2 tabs. More... | |
bool | changeCurrentOnDrag |
If true, then the current tab is automatically changed when dragging over the tabbar. More... | |
Properties inherited from QWidget | |
bool | modal |
whether the widget is a modal widget More... | |
Qt::WindowModality | windowModality |
which windows are blocked by the modal widget More... | |
bool | enabled |
whether the widget is enabled More... | |
QRect | geometry |
the geometry of the widget relative to its parent and excluding the window frame More... | |
QRect | frameGeometry |
geometry of the widget relative to its parent including any window frame More... | |
QRect | normalGeometry |
the geometry of the widget as it will appear when shown as a normal (not maximized or full screen) top-level widget More... | |
int | x |
the x coordinate of the widget relative to its parent including any window frame More... | |
int | y |
the y coordinate of the widget relative to its parent and including any window frame More... | |
QPoint | pos |
the position of the widget within its parent widget More... | |
QSize | frameSize |
the size of the widget including any window frame More... | |
QSize | size |
the size of the widget excluding any window frame More... | |
int | width |
the width of the widget excluding any window frame More... | |
int | height |
the height of the widget excluding any window frame More... | |
QRect | rect |
the internal geometry of the widget excluding any window frame More... | |
QRect | childrenRect |
the bounding rectangle of the widget's children More... | |
QRegion | childrenRegion |
the combined region occupied by the widget's children More... | |
QSizePolicy | sizePolicy |
the default layout behavior of the widget More... | |
QSize | minimumSize |
the widget's minimum size More... | |
QSize | maximumSize |
the widget's maximum size in pixels More... | |
int | minimumWidth |
the widget's minimum width in pixels More... | |
int | minimumHeight |
the widget's minimum height in pixels More... | |
int | maximumWidth |
the widget's maximum width in pixels More... | |
int | maximumHeight |
the widget's maximum height in pixels More... | |
QSize | sizeIncrement |
the size increment of the widget More... | |
QSize | baseSize |
the base size of the widget More... | |
QPalette | palette |
the widget's palette More... | |
QFont | font |
the font currently set for the widget More... | |
QCursor | cursor |
the cursor shape for this widget More... | |
bool | mouseTracking |
whether mouse tracking is enabled for the widget More... | |
bool | tabletTracking |
whether tablet tracking is enabled for the widget More... | |
bool | isActiveWindow |
whether this widget's window is the active window More... | |
Qt::FocusPolicy | focusPolicy |
the way the widget accepts keyboard focus More... | |
bool | focus |
whether this widget (or its focus proxy) has the keyboard input focus More... | |
Qt::ContextMenuPolicy | contextMenuPolicy |
how the widget shows a context menu More... | |
bool | updatesEnabled |
whether updates are enabled More... | |
bool | visible |
whether the widget is visible More... | |
bool | minimized |
whether this widget is minimized (iconified) More... | |
bool | maximized |
whether this widget is maximized More... | |
bool | fullScreen |
whether the widget is shown in full screen mode More... | |
QSize | sizeHint |
the recommended size for the widget More... | |
QSize | minimumSizeHint |
the recommended minimum size for the widget More... | |
bool | acceptDrops |
whether drop events are enabled for this widget More... | |
QString | windowTitle |
the window title (caption) More... | |
QIcon | windowIcon |
the widget's icon More... | |
QString | windowIconText |
the text to be displayed on the icon of a minimized window More... | |
double | windowOpacity |
The level of opacity for the window. More... | |
bool | windowModified |
whether the document shown in the window has unsaved changes More... | |
QString | accessibleName |
the widget's name as seen by assistive technologies More... | |
QString | accessibleDescription |
the widget's description as seen by assistive technologies More... | |
Qt::LayoutDirection | layoutDirection |
the layout direction for this widget. More... | |
bool | autoFillBackground |
whether the widget background is filled automatically More... | |
QString | styleSheet |
the widget's style sheet More... | |
QLocale | locale |
the widget's locale More... | |
QString | windowFilePath |
the file path associated with a widget More... | |
Qt::InputMethodHints | inputMethodHints |
What input method specific hints the widget has. More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Friends | |
class | QAccessibleTabBar |
The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs.
\inmodule QtWidgets
QTabBar is straightforward to use; it draws the tabs using one of the predefined \l{QTabBar::Shape}{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 \l{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 \l shape property defines the tabs' appearance. The choice of shape is a matter of taste, although tab dialogs (for preferences and similar) invariably use \l RoundedNorth. Tab controls in windows other than dialogs almost always use either \l RoundedSouth or \l TriangularSouth. Many spreadsheets and other tab controls in which all the pages are essentially similar use \l TriangularSouth, whereas \l RoundedSouth is used mostly when the pages are different (e.g. a multi-page tool palette). The default in QTabBar is \l 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, \l 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:
\list
For subclasses, you might also need the tabRect() functions which returns the visual geometry of a single tab.
\table 100% \row
This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also the current tab.
\value SelectLeftTab Select the tab to the left of the one being removed.
\value SelectRightTab Select the tab to the right of the one being removed.
\value SelectPreviousTab Select the previously selected tab.
Enumerator | |
---|---|
SelectLeftTab | |
SelectRightTab | |
SelectPreviousTab |
enum QTabBar::Shape |
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.
\value RoundedNorth The normal rounded look above the pages
\value RoundedSouth The normal rounded look below the pages
\value RoundedWest The normal rounded look on the left side of the pages
\value RoundedEast The normal rounded look on the right side the pages
\value TriangularNorth Triangular tabs above the pages.
\value TriangularSouth Triangular tabs similar to those used in the Excel spreadsheet, for example
\value TriangularWest Triangular tabs on the left of the pages.
\value TriangularEast Triangular tabs on the right of the pages.
Enumerator | |
---|---|
RoundedNorth | |
RoundedSouth | |
RoundedWest | |
RoundedEast | |
TriangularNorth | |
TriangularSouth | |
TriangularWest | |
TriangularEast |
Creates a new tab bar with the given parent.
Definition at line 878 of file qtabbar.cpp.
QTabBar::~QTabBar | ( | ) |
Destroys the tab bar.
Definition at line 889 of file qtabbar.cpp.
QString QTabBar::accessibleTabName | ( | int | index | ) | const |
Returns the accessibleName of the tab at position index, or an empty string if index is out of range.
Definition at line 2860 of file qtabbar.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Adds a new tab with icon icon and text text. Returns the new tab's index.
Definition at line 956 of file qtabbar.cpp.
Adds a new tab with text text. Returns the new tab's index.
Definition at line 945 of file qtabbar.cpp.
bool QTabBar::autoHide | ( | ) | const |
Definition at line 2743 of file qtabbar.cpp.
bool QTabBar::changeCurrentOnDrag | ( | ) | const |
Definition at line 2774 of file qtabbar.cpp.
\reimp
Reimplemented from QWidget.
Definition at line 2463 of file qtabbar.cpp.
int QTabBar::count | ( | ) | const |
Definition at line 1502 of file qtabbar.cpp.
|
signal |
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)
int QTabBar::currentIndex | ( | ) | const |
Definition at line 1418 of file qtabbar.cpp.
bool QTabBar::documentMode | ( | ) | const |
Definition at line 2719 of file qtabbar.cpp.
bool QTabBar::drawBase | ( | ) | const |
Definition at line 935 of file qtabbar.cpp.
Qt::TextElideMode QTabBar::elideMode | ( | ) | const |
Definition at line 2512 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 1694 of file qtabbar.cpp.
bool QTabBar::expanding | ( | ) | const |
Definition at line 2670 of file qtabbar.cpp.
|
overrideprotectedvirtual |
QSize QTabBar::iconSize | ( | ) | const |
|
protectedvirtual |
Initialize option with the values from the tab at tabIndex. This method is useful for subclasses when they need a QStyleOptionTab, but don't want to fill in all the information themselves.
Definition at line 244 of file qtabbar.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
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.
Definition at line 983 of file qtabbar.cpp.
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.
Definition at line 966 of file qtabbar.cpp.
bool QTabBar::isMovable | ( | ) | const |
bool QTabBar::isTabEnabled | ( | int | index | ) | const |
Returns true
if the tab at position index is enabled; otherwise returns false
.
Definition at line 1129 of file qtabbar.cpp.
bool QTabBar::isTabVisible | ( | int | index | ) | const |
Returns true if the tab at position index is visible; otherwise returns false.
Definition at line 1163 of file qtabbar.cpp.
\reimp
Reimplemented from QWidget.
Definition at line 2376 of file qtabbar.cpp.
|
overridevirtual |
|
protectedvirtual |
Returns the minimum tab size hint for the tab at position index.
Definition at line 1575 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 2362 of file qtabbar.cpp.
|
overrideprotectedvirtual |
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 2135 of file qtabbar.cpp.
|
overrideprotectedvirtual |
void QTabBar::moveTab | ( | int | from, |
int | to | ||
) |
Moves the item at index position from to index position to.
Definition at line 2020 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 1821 of file qtabbar.cpp.
void QTabBar::removeTab | ( | int | index | ) |
Removes the tab at position index.
Definition at line 1037 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 1809 of file qtabbar.cpp.
QTabBar::SelectionBehavior QTabBar::selectionBehaviorOnRemove | ( | ) | const |
Definition at line 2648 of file qtabbar.cpp.
Sets the accessibleName of the tab at position index to name.
Definition at line 2845 of file qtabbar.cpp.
void QTabBar::setAutoHide | ( | bool | hide | ) |
void QTabBar::setChangeCurrentOnDrag | ( | bool | change | ) |
Definition at line 2780 of file qtabbar.cpp.
|
slot |
Definition at line 1427 of file qtabbar.cpp.
void QTabBar::setDocumentMode | ( | bool | set | ) |
void QTabBar::setDrawBase | ( | bool | drawTheBase | ) |
Definition at line 926 of file qtabbar.cpp.
void QTabBar::setElideMode | ( | Qt::TextElideMode | mode | ) |
Definition at line 2518 of file qtabbar.cpp.
void QTabBar::setExpanding | ( | bool | enabled | ) |
void QTabBar::setMovable | ( | bool | movable | ) |
void QTabBar::setSelectionBehaviorOnRemove | ( | QTabBar::SelectionBehavior | behavior | ) |
Definition at line 2654 of file qtabbar.cpp.
void QTabBar::setTabButton | ( | int | index, |
ButtonPosition | position, | ||
QWidget * | widget | ||
) |
Sets widget on the tab index. The widget is placed on the left or right hand side depending upon the position.
Any previously set widget in position is hidden.
The tab bar will take ownership of the widget and so all widgets set here will be deleted by the tab bar when it is destroyed unless you separately reparent the widget after setting some other widget (or \nullptr).
Definition at line 2801 of file qtabbar.cpp.
Sets the data of the tab at position index to data.
Definition at line 1346 of file qtabbar.cpp.
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.
Definition at line 1141 of file qtabbar.cpp.
Sets the icon of the tab at position index to icon.
Definition at line 1276 of file qtabbar.cpp.
void QTabBar::setTabsClosable | ( | bool | closable | ) |
Definition at line 2575 of file qtabbar.cpp.
Sets the text of the tab at position index to text.
Definition at line 1216 of file qtabbar.cpp.
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.
Definition at line 1252 of file qtabbar.cpp.
void QTabBar::setTabVisible | ( | int | index, |
bool | visible | ||
) |
If visible is true, make the tab at position index visible, otherwise make it hidden.
Definition at line 1176 of file qtabbar.cpp.
void QTabBar::setUsesScrollButtons | ( | bool | useButtons | ) |
Definition at line 2545 of file qtabbar.cpp.
QTabBar::Shape QTabBar::shape | ( | ) | const |
Definition at line 901 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QWidget.
Definition at line 1674 of file qtabbar.cpp.
|
overridevirtual |
Definition at line 1395 of file qtabbar.cpp.
|
signal |
This signal is emitted when user clicks on a tab at an index.
index is the index of a clicked tab, or -1 if no tab is under the cursor.
|
signal |
This signal is emitted when the user double clicks on a tab at index.
index refers to the tab clicked, or -1 if no tab is under the cursor.
QWidget * QTabBar::tabButton | ( | int | index, |
ButtonPosition | position | ||
) | const |
Returns the widget set a tab index and position or \nullptr if one is not set.
Definition at line 2831 of file qtabbar.cpp.
|
signal |
This signal is emitted when the close button on a tab is clicked. The index is the index that should be removed.
QVariant QTabBar::tabData | ( | int | index | ) | const |
Returns the data of the tab at position index, or a null variant if index is out of range.
Definition at line 1357 of file qtabbar.cpp.
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.
Definition at line 1265 of file qtabbar.cpp.
|
protectedvirtual |
This virtual handler is called after a new tab was added or inserted at position index.
Definition at line 1646 of file qtabbar.cpp.
|
protectedvirtual |
This virtual handler is called whenever the tab layout changes.
Definition at line 1667 of file qtabbar.cpp.
|
signal |
This signal is emitted when the tab has moved the tab at index position from to index position to.
note: QTabWidget will automatically move the page when this signal is emitted from its tab bar.
QRect QTabBar::tabRect | ( | int | index | ) | const |
Returns the visual rectangle of the tab at position index, or a null rectangle if index is hidden, or out of range.
Definition at line 1369 of file qtabbar.cpp.
|
protectedvirtual |
This virtual handler is called after a tab was removed from position index.
Definition at line 1657 of file qtabbar.cpp.
bool QTabBar::tabsClosable | ( | ) | const |
Definition at line 2569 of file qtabbar.cpp.
|
protectedvirtual |
Returns the size hint for the tab at position index.
Definition at line 1589 of file qtabbar.cpp.
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.
Definition at line 1205 of file qtabbar.cpp.
QColor QTabBar::tabTextColor | ( | int | index | ) | const |
Returns the text color of the tab with the given index, or a invalid color if index is out of range.
Definition at line 1237 of file qtabbar.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 2487 of file qtabbar.cpp.
bool QTabBar::usesScrollButtons | ( | ) | const |
Definition at line 2540 of file qtabbar.cpp.
|
readwrite |
If true, the tab bar is automatically hidden when it contains less than 2 tabs.
By default, this property is false.
|
readwrite |
|
readwrite |
|
readwrite |
Whether or not the tab bar is rendered in a mode suitable for the main window.
This property is used as a hint for styles to draw the tabs in a different way then they would normally look in a tab widget. On \macos this will look similar to the tabs in Safari or Sierra's Terminal.app.
|
readwrite |
defines whether or not tab bar should draw its base.
If true then QTabBar draws a base in relation to the styles overlap. Otherwise only the tabs are drawn.
|
readwrite |
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.
|
readwrite |
When expanding is true QTabBar will expand the tabs to use the empty space.
By default the value is true.
|
readwrite |
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.
|
readwrite |
|
readwrite |
What tab should be set as current when removeTab is called if the removed tab is also the current tab.
By default the value is SelectRightTab.
|
readwrite |
|
readwrite |
Whether or not a tab bar should place close buttons on each tab.
When tabsClosable is set to true a close button will appear on the tab on either the left or right hand side depending upon the style. When the button is clicked the tab the signal tabCloseRequested will be emitted.
By default the value is false.
|
readwrite |
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-dependent.