CopperSpice API  1.9.2
QTabWidget Class Reference

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

Inheritance diagram for QTabWidget:
QWidget QObject QPaintDevice

Public Types

enum  TabPosition
 
enum  TabShape
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 

Public Signals

void currentChanged (int index)
 
void tabBarClicked (int index)
 
void tabBarDoubleClicked (int index)
 
void tabCloseRequested (int index)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setCurrentIndex (int index)
 
void setCurrentWidget (QWidget *widget)
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QTabWidget (QWidget *parent=nullptr)
 
 ~QTabWidget ()
 
int addTab (QWidget *widget, const QIcon &icon, const QString &label)
 
int addTab (QWidget *widget, const QString &label)
 
void clear ()
 
QWidgetcornerWidget (Qt::Corner corner=Qt::TopRightCorner) const
 
int count () const
 
int currentIndex () const
 
QWidgetcurrentWidget () const
 
bool documentMode () const
 
Qt::TextElideMode elideMode () const
 
bool hasHeightForWidth () const override
 
int heightForWidth (int width) const override
 
QSize iconSize () const
 
int indexOf (QWidget *widget) const
 
int insertTab (int index, QWidget *widget, const QIcon &icon, const QString &label)
 
int insertTab (int index, QWidget *widget, const QString &label)
 
bool isMovable () const
 
bool isTabEnabled (int index) const
 
QSize minimumSizeHint () const override
 
void removeTab (int index)
 
void setCornerWidget (QWidget *widget, Qt::Corner corner=Qt::TopRightCorner)
 
void setDocumentMode (bool set)
 
void setElideMode (Qt::TextElideMode value)
 
void setIconSize (const QSize &size)
 
void setMovable (bool movable)
 
void setTabBarAutoHide (bool enable)
 
void setTabEnabled (int index, bool enable)
 
void setTabIcon (int index, const QIcon &icon)
 
void setTabPosition (TabPosition value)
 
void setTabsClosable (bool closeable)
 
void setTabShape (TabShape s)
 
void setTabText (int index, const QString &label)
 
void setTabToolTip (int index, const QString &tip)
 
void setTabWhatsThis (int index, const QString &text)
 
void setUsesScrollButtons (bool useButtons)
 
QSize sizeHint () const override
 
QTabBartabBar () const
 
bool tabBarAutoHide () const
 
QIcon tabIcon (int index) const
 
TabPosition tabPosition () const
 
bool tabsClosable () const
 
TabShape tabShape () const
 
QString tabText (int index) const
 
QString tabToolTip (int index) const
 
QString tabWhatsThis (int index) const
 
bool usesScrollButtons () const
 
QWidgetwidget (int index) const
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
bool hasMouseTracking () const
 
int height () const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void changeEvent (QEvent *event) override
 
bool event (QEvent *event) override
 
void initStyleOption (QStyleOptionTabWidgetFrame *option) const
 
void keyPressEvent (QKeyEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void resizeEvent (QResizeEvent *event) override
 
void setTabBar (QTabBar *tabBar)
 
void showEvent (QShowEvent *event) override
 
virtual void tabInserted (int index)
 
virtual void tabRemoved (int index)
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
virtual void contextMenuEvent (QContextMenuEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
virtual void focusInEvent (QFocusEvent *event)
 
bool focusNextChild ()
 
virtual bool focusNextPrevChild (bool next)
 
virtual void focusOutEvent (QFocusEvent *event)
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void mouseMoveEvent (QMouseEvent *event)
 
virtual void mousePressEvent (QMouseEvent *event)
 
virtual void mouseReleaseEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 count
 
 currentIndex
 
 documentMode
 
 elideMode
 
 iconSize
 
 movable
 
 tabBarAutoHide
 
 tabPosition
 
 tabsClosable
 
 tabShape
 
 usesScrollButtons
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QTabWidget class provides a stack of tabbed widgets. This class provides a "tab bar" and a "area" that is used to display the page for each tab.

By default the tab bar is shown above the page area, however different configurations are available using QTabPosition. Each tab or page is associated with a different widget. Only the current page is shown in the area, all the other pages are hidden. The user can show a different page by clicking on the corresponding tab or by pressing the Alt+letter shortcut if one exists.

These are the typical steps to create a QTabWidget.

  1. Create a QTabWidget.
  2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
  3. Insert child widgets into the page widget, using layouts to position them as normal.
  4. Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.

The position of the tabs is defined by the tabPosition property and the shape is set by the tabShape property.

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

The current page index is available by calling currentIndex() and the current page widget can be retrieved by calling currentWidget(). You can retrieve a pointer to a page widget with a given index using widget(). To find the index position of a widget use 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 and its associated page 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 can not 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 widget Screenshot of a Mac OS X style tab widget Screenshot of a Fusion style tab widget
Windows XP style tab widget. Mac OS X style tab widget. Fusion style tab widget.
See also
QStackedWidget, QTabBar, QToolBox

Member Enumeration Documentation

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.

This enum type defines the shape of the tabs.

ConstantValueDescription
QTabWidget::Rounded0 The tabs are drawn with a rounded look.This is the default shape.
QTabWidget::Triangular1 The tabs are drawn with a triangular look.

Constructor & Destructor Documentation

QTabWidget::QTabWidget ( QWidget parent = nullptr)
explicit

Constructs a tabbed widget with the given parent.

QTabWidget::~QTabWidget ( )

Destroys the tabbed widget.

Method Documentation

int QTabWidget::addTab ( QWidget widget,
const QIcon icon,
const QString label 
)

Adds a tab with the given widget, icon, and label to the tab widget, and returns the index of the tab in the tab bar.

int QTabWidget::addTab ( QWidget widget,
const QString label 
)

Adds a tab with the given widget and label to the tab widget. Returns the index of the tab in the tab bar. If the tab's label contains an ampersand the letter following the ampersand is used as a shortcut for the tab. For example if the label is "Bro&amp;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 its 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()
void QTabWidget::changeEvent ( QEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::changeEvent()

void QTabWidget::clear ( )

Removes all the pages, but does not delete them. Calling this function is equivalent to calling removeTab() until the tab widget is empty.

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

Returns the widget shown in the corner of the tab widget or a nullptr.

See also
setCornerWidget()
int QTabWidget::count ( ) const

Returns the value of the property.

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, or -1 if there is not a new one (for example, if there are no widgets in the QTabWidget)

See also
currentWidget(), currentIndex
int QTabWidget::currentIndex ( ) const

Returns the value of the property.

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(), setCurrentWidget()
bool QTabWidget::documentMode ( ) const

Returns the value of the property.

Qt::TextElideMode QTabWidget::elideMode ( ) const

Returns the value of the property.

bool QTabWidget::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

bool QTabWidget::hasHeightForWidth ( ) const
overridevirtual

Reimplemented from QWidget::hasHeightForWidth()

int QTabWidget::heightForWidth ( int  width) const
overridevirtual

Reimplemented from QWidget::heightForWidth()

QSize QTabWidget::iconSize ( ) const

Returns the value of the property.

int QTabWidget::indexOf ( QWidget widget) const

Returns the index position of the page occupied by the widget or -1 if the widget can not be found.

void QTabWidget::initStyleOption ( QStyleOptionTabWidgetFrame option) const
protected

Initialize option with the values from this QTabWidget. This method is useful for subclasses when they need a QStyleOptionTabWidgetFrame, but do not want to fill in all the information themselves.

See also
QStyleOption::initFrom(), QTabBar::initStyleOption()
int QTabWidget::insertTab ( int  index,
QWidget widget,
const QIcon icon,
const QString label 
)

Inserts a tab with the given label, widget, and icon into the tab widget at the specified index, and returns the index of the inserted tab in the tab bar.

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

Inserts a tab with the given label and widget into the tab widget at the specified index, and returns the index of the inserted tab in the tab bar.

The label is displayed in the tab and may vary in appearance depending on the configuration of the tab widget. If the tab's label contains an ampersand, the letter following the ampersand is used as a shortcut for the tab. For example if the label is "Bro&amp;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 method is called the new page becomes the current widget. Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current widget.

Note
If you call insertTab() after show(), the layout system will try to adjust to the changes in its 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()
bool QTabWidget::isMovable ( ) const

Returns the value of the property.

bool QTabWidget::isTabEnabled ( int  index) const

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

See also
setTabEnabled(), QWidget::isEnabled()
void QTabWidget::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyPressEvent()

QSize QTabWidget::minimumSizeHint ( ) const
overridevirtual

Returns a suitable minimum size for the tab widget.

Reimplemented from QWidget::minimumSizeHint()

void QTabWidget::paintEvent ( QPaintEvent event)
overrideprotectedvirtual

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

Reimplemented from QWidget::paintEvent()

void QTabWidget::removeTab ( int  index)

Removes the tab at position index from this stack of widgets. The page widget itself is not deleted.

See also
addTab(), insertTab()
void QTabWidget::resizeEvent ( QResizeEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::resizeEvent()

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. The geometry of the widget is determined based on the widget sizeHint() and the style(). Only the horizontal element of the corner will be used. Passing a nullptr shows no widget in the corner. Any previously set corner widget is hidden.

The widget becomes a child of the current QTabWidget. Corner widgets are designed for North and South tab positions and other orientations are known to not work properly.

See also
cornerWidget(), setTabPosition()
void QTabWidget::setCurrentIndex ( int  index)
slot

Sets the value of the property to index.

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(), currentWidget()
void QTabWidget::setDocumentMode ( bool  set)

Sets the value of the property to set.

void QTabWidget::setElideMode ( Qt::TextElideMode  value)

Sets the value of the property to value.

void QTabWidget::setIconSize ( const QSize size)

Sets the value of the property to size.

void QTabWidget::setMovable ( bool  movable)

Sets the value of the property to movable.

void QTabWidget::setTabBar ( QTabBar tabBar)
protected

Replaces the dialog's QTabBar heading with the tab bar tabBar. This must be called before any tabs have been added, or the behavior is undefined.

See also
tabBar()
void QTabWidget::setTabBarAutoHide ( bool  enable)

Sets the value of the property to enable.

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() rather than keeping a separate flag. A disabled tab/page may still 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(), QWidget::setEnabled()
void QTabWidget::setTabIcon ( int  index,
const QIcon icon 
)

Sets the icon for the tab at position index.

See also
tabIcon()
void QTabWidget::setTabPosition ( TabPosition  value)

Sets the value of the property to value.

void QTabWidget::setTabsClosable ( bool  closeable)

Sets the value of the property to closeable.

void QTabWidget::setTabShape ( TabShape  s)

Sets the value of the property to s.

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.

See also
tabWhatsThis()
void QTabWidget::setUsesScrollButtons ( bool  useButtons)

Sets the value of the property to useButtons.

void QTabWidget::showEvent ( QShowEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::showEvent()

QSize QTabWidget::sizeHint ( ) const
overridevirtual

Reimplemented from QWidget::sizeHint()

QTabBar * QTabWidget::tabBar ( ) const

Returns the current QTabBar.

See also
setTabBar()
bool QTabWidget::tabBarAutoHide ( ) const

Returns the value of the property.

void QTabWidget::tabBarClicked ( int  index)
signal

This signal is emitted when the user clicks on a tab. The index refers to the tab clicked or -1 if no tab is under the cursor.

void QTabWidget::tabBarDoubleClicked ( int  index)
signal

This signal is emitted when the user double clicks on a tab at an index. The index refers to the tab which was clicked or -1 if no tab is under the cursor.

void QTabWidget::tabCloseRequested ( int  index)
signal

This signal is emitted when the close button on a tab is clicked. The index is the index that should be removed.

See also
setTabsClosable()
QIcon QTabWidget::tabIcon ( int  index) const

Returns the icon for the tab on the page at position index.

See also
setTabIcon()
void QTabWidget::tabInserted ( int  index)
protectedvirtual

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

See also
tabRemoved()
TabPosition QTabWidget::tabPosition ( ) const

Returns the value of the property.

void QTabWidget::tabRemoved ( int  index)
protectedvirtual

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

See also
tabInserted()
bool QTabWidget::tabsClosable ( ) const

Returns the value of the property.

TabShape QTabWidget::tabShape ( ) const

Returns the value of the property.

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.

See also
setTabWhatsThis()
bool QTabWidget::usesScrollButtons ( ) const

Returns the value of the property.

QWidget * QTabWidget::widget ( int  index) const

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

Property Documentation

QTabWidget::count

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

By default, this property contains a value of 0.

PropertiesClass Methods
read count
QTabWidget::currentIndex

This property holds the index position of the current tab page. The current index is -1 if there is no current widget. By default, this property contains a value of -1 because there are initially no tabs in the widget.

PropertiesClass Methods
read currentIndex
write setCurrentIndex
notify currentChanged
QTabWidget::documentMode

When this property is set the tab widget frame is not rendered. This mode is useful for showing documents in tabs where the page covers most of the tab widget area.

This is the same as 'document mode' on Mac OS X.

See also
QTabWidget::elideMode, QTabBar::documentMode, QTabBar::usesScrollButtons, QStyle::StyleHint
PropertiesClass Methods
read documentMode
write setDocumentMode
QTabWidget::elideMode

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.

See also
QTabBar::elideMode, QTabWidget::usesScrollButtons, QStyle::StyleHint
PropertiesClass Methods
read elideMode
write setElideMode
QTabWidget::iconSize

This property holds the size for icons in the tab bar. The default value is style-dependent. This is the maximum size that the icons will have. Icons are not scaled up if they are of smaller size.

See also
QTabBar::iconSize
PropertiesClass Methods
read iconSize
write setIconSize
QTabWidget::movable

This property holds this property holds whether the user can move the tabs within the tabbar area.

By default this property is false.

PropertiesClass Methods
read isMovable
write setMovable
QTabWidget::tabBarAutoHide

If true the tab bar is automatically hidden when it contains less than 2 tabs. By default this property is false.

See also
QWidget::visible
PropertiesClass Methods
read tabBarAutoHide
write setTabBarAutoHide
QTabWidget::tabPosition

This property holds the position of the tabs in this tab widget. Possible values for this property are described by the TabPosition enum.

By default this property is set to North.

See also
QTabWidget::TabPosition
PropertiesClass Methods
read tabPosition
write setTabPosition
QTabWidget::tabsClosable

This property holds whether close buttons are automatically added to each tab.

See also
QTabBar::tabsClosable()
PropertiesClass Methods
read tabsClosable
write setTabsClosable
QTabWidget::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.

See also
QTabWidget::TabShape
PropertiesClass Methods
read tabShape
write setTabShape
QTabWidget::usesScrollButtons

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 dependent.

See also
QTabWidget::elideMode, QTabBar::usesScrollButtons, QStyle::StyleHint
PropertiesClass Methods
read usesScrollButtons
write setUsesScrollButtons