Qt5 Virtual Slot

Posted onby
  1. Qt Virtual Slot
  2. Qt5 Virtual Slots

Qt 5.12 Long Term Support Release: New Features in Qt 5.12 - Qt 5.15 Standard Support. Long Term Support Release New Features in Qt 5.15 - Qt 6.0 Development: New Features in Qt 6.0 - Install / Build. Install Qt 5 on openSUSE. Transition from Qt 4.x to Qt5‏‎ New Signal Slot Syntax‏‎. virtual slot void QDialog:: open Shows the dialog as a window modal dialog, returning immediately. This function was introduced in Qt 4.5. See also exec, show, result, and setWindowModality. virtual slot void QDialog:: reject Hides the modal dialog and sets the result code to Rejected. See also accept and done.

Slots

This is the sequel of my previous article explaining the implementation details of the signals and slots.In the Part 1, we have seenthe general principle and how it works with the old syntax.In this blog post, we will see the implementation details behind thenew function pointerbased syntax in Qt5.

New Syntax in Qt5

In Qt 5, at least, if you're using the obj-ptr, member-func-ptr, obj-ptr, member-func-ptr version of connect, none of your slots need to be declared as such. – Kyle Strand Jul 13 '16 at 17:01 have to add some really weird behavior: when you mark the overriden methods as slots in the header of the subclass, slots get called all the time even. Signals and slots are used for communication between objects. The signals and slots mechanism is a central feature of Qt and probably the part that differs most from the features provided by other frameworks. Signals and slots are made possible by Qt's meta-object system. If i create a class from a base class with virtual slots, the slots never get called with the new connect-flavour. If i use the old connect-syntax, the slot gets called. What could be the problem? @ class BaseClass: public QObject public slots: virt.

The new syntax looks like this:

Why the new syntax?

I already explained the advantages of the new syntax in adedicated blog entry.To summarize, the new syntax allows compile-time checking of the signals and slots. It also allowsautomatic conversion of the arguments if they do not have the same types.As a bonus, it enables the support for lambda expressions.

New overloads

There was only a few changes required to make that possible.
The main idea is to have new overloads to QObject::connect which take the pointersto functions as arguments instead of char*

There are three new static overloads of QObject::connect: (not actual code)

The first one is the one that is much closer to the old syntax: you connect a signal from the senderto a slot in a receiver object.The two other overloads are connecting a signal to a static function or a functor object withouta receiver.

They are very similar and we will only analyze the first one in this article.

Pointer to Member Functions

Before continuing my explanation, I would like to open a parenthesis totalk a bit about pointers to member functions.

Here is a simple sample code that declares a pointer to member function and calls it.

Pointers to member and pointers to member functions are usually part of the subset of C++ that is not much used and thus lesser known.
The good news is that you still do not really need to know much about them to use Qt and its new syntax. All you need to remember is to put the & before the name of the signal in your connect call. But you will not need to cope with the ::*, .* or ->* cryptic operators.

These cryptic operators allow you to declare a pointer to a member or access it.The type of such pointers includes the return type, the class which owns the member, the types of each argumentand the const-ness of the function.

You cannot really convert pointer to member functions to anything and in particular not tovoid* because they have a different sizeof.
If the function varies slightly in signature, you cannot convert from one to the other.For example, even converting from void (MyClass::*)(int) const tovoid (MyClass::*)(int) is not allowed.(You could do it with reinterpret_cast; but that would be an undefined behaviour if you callthem, according to the standard)

Pointer to member functions are not just like normal function pointers.A normal function pointer is just a normal pointer the address where thecode of that function lies.But pointer to member function need to store more information:member functions can be virtual and there is also an offset to apply to thehidden this in case of multiple inheritance.
sizeof of a pointer to a member function can evenvary depending of the class.This is why we need to take special care when manipulating them.

Type Traits: QtPrivate::FunctionPointer

Let me introduce you to the QtPrivate::FunctionPointer type trait.
A trait is basically a helper class that gives meta data about a given type.Another example of trait in Qt isQTypeInfo.

What we will need to know in order to implement the new syntax is information about a function pointer.

The template<typename T> struct FunctionPointer will give us informationabout T via its member.

  • ArgumentCount: An integer representing the number of arguments of the function.
  • Object: Exists only for pointer to member function. It is a typedef to the class of which the function is a member.
  • Arguments: Represents the list of argument. It is a typedef to a meta-programming list.
  • call(T &function, QObject *receiver, void **args): A static function that will call the function, applying the given parameters.

Qt still supports C++98 compiler which means we unfortunately cannot require support for variadic templates.Therefore we had to specialize our trait function for each number of arguments.We have four kinds of specializationd: normal function pointer, pointer to member function,pointer to const member function and functors.For each kind, we need to specialize for each number of arguments. We support up to six arguments.We also made a specialization using variadic templateso we support arbitrary number of arguments if the compiler supports variadic templates.

The implementation of FunctionPointer lies inqobjectdefs_impl.h.

QObject::connect

The implementation relies on a lot of template code. I am not going to explain all of it.

Here is the code of the first new overload fromqobject.h:

You notice in the function signature that sender and receiverare not just QObject* as the documentation points out. They are pointers totypename FunctionPointer::Object instead.This uses SFINAEto make this overload only enabled for pointers to member functionsbecause the Object only exists in FunctionPointer ifthe type is a pointer to member function.

We then start with a bunch ofQ_STATIC_ASSERT.They should generate sensible compilation error messages when the user made a mistake.If the user did something wrong, it is important that he/she sees an error hereand not in the soup of template code in the _impl.h files.We want to hide the underlying implementation from the user who should not needto care about it.
That means that if you ever you see a confusing error in the implementation details,it should be considered as a bug that should be reported.

We then allocate a QSlotObject that is going to be passed to connectImpl().The QSlotObject is a wrapper around the slot that will help calling it. It alsoknows the type of the signal arguments so it can do the proper type conversion.
We use List_Left to only pass the same number as argument as the slot, which allows connectinga signal with many arguments to a slot with less arguments.

QObject::connectImpl is the private internal functionthat will perform the connection.It is similar to the original syntax, the difference is that instead of storing amethod index in the QObjectPrivate::Connection structure,we store a pointer to the QSlotObjectBase.

The reason why we pass &slot as a void** is only tobe able to compare it if the type is Qt::UniqueConnection.

We also pass the &signal as a void**.It is a pointer to the member function pointer. (Yes, a pointer to the pointer)

Signal Index

We need to make a relationship between the signal pointer and the signal index.
We use MOC for that. Yes, that means this new syntaxis still using the MOC and that there are no plans to get rid of it :-).

MOC will generate code in qt_static_metacallthat compares the parameter and returns the right index.connectImpl will call the qt_static_metacall function with thepointer to the function pointer.

Once we have the signal index, we can proceed like in the other syntax.

Qt Virtual Slot

The QSlotObjectBase

QSlotObjectBase is the object passed to connectImplthat represents the slot.

Before showing the real code, this is what QObject::QSlotObjectBasewas in Qt5 alpha:

It is basically an interface that is meant to be re-implemented bytemplate classes implementing the call and comparison of thefunction pointers.

It is re-implemented by one of the QSlotObject, QStaticSlotObject orQFunctorSlotObject template class.

Fake Virtual Table

The problem with that is that each instantiation of those object would need to create a virtual table which contains not only pointer to virtual functionsbut also lot of information we do not need such asRTTI.That would result in lot of superfluous data and relocation in the binaries.

In order to avoid that, QSlotObjectBase was changed not to be a C++ polymorphic class.Virtual functions are emulated by hand.

The m_impl is a (normal) function pointer which performsthe three operations that were previously virtual functions. The 're-implementations'set it to their own implementation in the constructor.

Please do not go in your code and replace all your virtual functions by such ahack because you read here it was good.This is only done in this case because almost every call to connectwould generate a new different type (since the QSlotObject has template parameterswich depend on signature of the signal and the slot).

Protected, Public, or Private Signals.

Signals were protected in Qt4 and before. It was a design choice as signals should be emittedby the object when its change its state. They should not be emitted fromoutside the object and calling a signal on another object is almost always a bad idea.

However, with the new syntax, you need to be able take the addressof the signal from the point you make the connection.The compiler would only let you do that if you have access to that signal.Writing &Counter::valueChanged would generate a compiler errorif the signal was not public.

In Qt 5 we had to change signals from protected to public.This is unfortunate since this mean anyone can emit the signals.We found no way around it. We tried a trick with the emit keyword. We tried returning a special value.But nothing worked.I believe that the advantages of the new syntax overcome the problem that signals are now public.

Sometimes it is even desirable to have the signal private. This is the case for example inQAbstractItemModel, where otherwise, developers tend to emit signalfrom the derived class which is not what the API wants.There used to be a pre-processor trick that made signals privatebut it broke the new connection syntax.
A new hack has been introduced.QPrivateSignal is a dummy (empty) struct declared private in the Q_OBJECTmacro. It can be used as the last parameter of the signal. Because it is private, only the objecthas the right to construct it for calling the signal.MOC will ignore the QPrivateSignal last argument while generating signature information.See qabstractitemmodel.h for an example.

More Template Code

The rest of the code is inqobjectdefs_impl.h andqobject_impl.h.It is mostly standard dull template code.

I will not go into much more details in this article,but I will just go over few items that are worth mentioning.

Meta-Programming List

As pointed out earlier, FunctionPointer::Arguments is a listof the arguments. The code needs to operate on that list:iterate over each element, take only a part of it or select a given item.

That is why there isQtPrivate::List that can represent a list of types. Some helpers to operate on it areQtPrivate::List_Select andQtPrivate::List_Left, which give the N-th element in the list and a sub-list containingthe N first elements.

The implementation of List is different for compilers that support variadic templates and compilers that do not.

With variadic templates, it is atemplate<typename... T> struct List;. The list of arguments is just encapsulatedin the template parameters.
For example: the type of a list containing the arguments (int, QString, QObject*) would simply be:

Qt5 virtual slots

Without variadic template, it is a LISP-style list: template<typename Head, typename Tail > struct List;where Tail can be either another List or void for the end of the list.
The same example as before would be:

ApplyReturnValue Trick

In the function FunctionPointer::call, the args[0] is meant to receive the return value of the slot.If the signal returns a value, it is a pointer to an object of the return type ofthe signal, else, it is 0.If the slot returns a value, we need to copy it in arg[0]. If it returns void, we do nothing.

The problem is that it is not syntaxically correct to use thereturn value of a function that returns void.Should I have duplicated the already huge amount of code duplication: once for the voidreturn type and the other for the non-void?No, thanks to the comma operator.

In C++ you can do something like that:

You could have replaced the comma by a semicolon and everything would have been fine.

Where it becomes interesting is when you call it with something that is not void:

There, the comma will actually call an operator that you even can overload.It is what we do inqobjectdefs_impl.h

ApplyReturnValue is just a wrapper around a void*. Then it can be usedin each helper. This is for example the case of a functor without arguments:

This code is inlined, so it will not cost anything at run-time.

Conclusion

This is it for this blog post. There is still a lot to talk about(I have not even mentioned QueuedConnection or thread safety yet), but I hope you found thisinterresting and that you learned here something that might help you as a programmer.

Update:The part 3 is available.

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

Header:#include <QTabBar>
qmake: QT += widgets
Inherits:QWidget

Public Types

enum ButtonPosition { LeftSide, RightSide }
enum SelectionBehavior { SelectLeftTab, SelectRightTab, SelectPreviousTab }
enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, ..., TriangularEast }

Properties

  • autoHide : bool
  • changeCurrentOnDrag : bool
  • count : const int
  • currentIndex : int
  • documentMode : bool
  • drawBase : bool
  • elideMode : Qt::TextElideMode
  • expanding : bool
  • iconSize : QSize
  • movable : bool
  • selectionBehaviorOnRemove : SelectionBehavior
  • shape : Shape
  • tabsClosable : bool
  • usesScrollButtons : bool
  • 59 properties inherited from QWidget
  • 1 property inherited from QObject

Public Functions

QTabBar(QWidget *parent = Q_NULLPTR)
~QTabBar()
QString accessibleTabName(int index) const
int addTab(const QString &text)
int addTab(const QIcon &icon, const QString &text)
bool autoHide() const
bool changeCurrentOnDrag() const
int count() const
int currentIndex() const
bool documentMode() const
bool drawBase() const
Qt::TextElideMode elideMode() const
bool expanding() const
QSize iconSize() const
int insertTab(int index, const QString &text)
int insertTab(int index, const QIcon &icon, const QString &text)
bool isMovable() const
bool isTabEnabled(int index) const
void moveTab(int from, int to)
void removeTab(int index)
SelectionBehavior selectionBehaviorOnRemove() const
void setAccessibleTabName(int index, const QString &name)
void setAutoHide(bool hide)
void setChangeCurrentOnDrag(bool change)
void setDocumentMode(bool set)
void setDrawBase(bool drawTheBase)
void setElideMode(Qt::TextElideMode)
void setExpanding(bool enabled)
void setIconSize(const QSize &size)
void setMovable(bool movable)
void setSelectionBehaviorOnRemove(SelectionBehavior behavior)
void setShape(Shape shape)
void setTabButton(int index, ButtonPosition position, QWidget *widget)
void setTabData(int index, const QVariant &data)
void setTabEnabled(int index, bool enabled)
void setTabIcon(int index, const QIcon &icon)
void setTabText(int index, const QString &text)
void setTabTextColor(int index, const QColor &color)
void setTabToolTip(int index, const QString &tip)
void setTabWhatsThis(int index, const QString &text)
void setTabsClosable(bool closable)
void setUsesScrollButtons(bool useButtons)
Shape shape() const
int tabAt(const QPoint &position) const
QWidget *tabButton(int index, ButtonPosition position) const
QVariant tabData(int index) const
QIcon tabIcon(int index) const
QRect tabRect(int index) const
QString tabText(int index) const
QColor tabTextColor(int index) const
QString tabToolTip(int index) const
QString tabWhatsThis(int index) const
bool tabsClosable() const
bool usesScrollButtons() const

Reimplemented Public Functions

virtual QSize minimumSizeHint() const
virtual QSize sizeHint() const
  • 214 public functions inherited from QWidget
  • 32 public functions inherited from QObject
  • 14 public functions inherited from QPaintDevice

Public Slots

  • 19 public slots inherited from QWidget
  • 1 public slot inherited from QObject

Signals

void currentChanged(int index)
void tabBarClicked(int index)
void tabBarDoubleClicked(int index)
void tabCloseRequested(int index)
void tabMoved(int from, int to)
  • 3 signals inherited from QWidget
  • 2 signals inherited from QObject

Protected Functions

void initStyleOption(QStyleOptionTab *option, int tabIndex) const
virtual QSize minimumTabSizeHint(int index) const
virtual void tabInserted(int index)
virtual void tabLayoutChange()
virtual void tabRemoved(int index)
virtual QSize tabSizeHint(int index) const

Reimplemented Protected Functions

virtual void changeEvent(QEvent *event)
virtual bool event(QEvent *event)
virtual void hideEvent(QHideEvent *)
virtual void keyPressEvent(QKeyEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintEvent(QPaintEvent *)
virtual void resizeEvent(QResizeEvent *)
virtual void showEvent(QShowEvent *)
virtual void timerEvent(QTimerEvent *event)
virtual void wheelEvent(QWheelEvent *event)
  • 35 protected functions inherited from QWidget
  • 9 protected functions inherited from QObject
  • 1 protected function inherited from QPaintDevice

Additional Inherited Members

  • 5 static public members inherited from QWidget
  • 11 static public members inherited from QObject
  • 1 protected slot inherited from 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:

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

A tab bar shown in the Fusion widget style.
A truncated tab bar shown in the Fusion widget style.

See also QTabWidget.

Member Type Documentation

enum QTabBar::ButtonPosition

This enum type lists the location of the widget on a tab.

ConstantValueDescription
QTabBar::LeftSide0Left side of the tab.
QTabBar::RightSide1Right side of the tab.

This enum was introduced or modified in Qt 4.5.

enum QTabBar::SelectionBehavior

This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also the current tab.

ConstantValueDescription
QTabBar::SelectLeftTab0Select the tab to the left of the one being removed.
QTabBar::SelectRightTab1Select the tab to the right of the one being removed.
QTabBar::SelectPreviousTab2Select the previously selected tab.

This enum was introduced or modified in Qt 4.5.

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.

ConstantValueDescription
QTabBar::RoundedNorth0The normal rounded look above the pages
QTabBar::RoundedSouth1The normal rounded look below the pages
QTabBar::RoundedWest2The normal rounded look on the left side of the pages
QTabBar::RoundedEast3The normal rounded look on the right side the pages
QTabBar::TriangularNorth4Triangular tabs above the pages.
QTabBar::TriangularSouth5Triangular tabs similar to those used in the Excel spreadsheet, for example
QTabBar::TriangularWest6Triangular tabs on the left of the pages.
QTabBar::TriangularEast7Triangular tabs on the right of the pages.

Property Documentation

autoHide : bool

If true, the tab bar is automatically hidden when it contains less than 2 tabs.

By default, this property is false.

This property was introduced in Qt 5.4.

Access functions:

bool autoHide() const
void setAutoHide(bool hide)

See also QWidget::visible.

changeCurrentOnDrag : bool

If true, then the current tab is automatically changed when dragging over the tabbar.

Note: You should also set acceptDrops property to true to make this feature work.

By default, this property is false.

This property was introduced in Qt 5.4.

Access functions:

bool changeCurrentOnDrag() const
void setChangeCurrentOnDrag(bool change)

count : const int

This property holds the number of tabs in the tab bar

Access functions:

currentIndex : int

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:

int currentIndex() const
void setCurrentIndex(int index)

Notifier signal:

documentMode : bool

This property holds 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.

This property was introduced in Qt 4.5.

Access functions:

bool documentMode() const
void setDocumentMode(bool set)

See also QTabWidget::documentMode.

drawBase : bool

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:

bool drawBase() const
void setDrawBase(bool drawTheBase)

See also QStyle::pixelMetric(), QStyle::PM_TabBarBaseOverlap, and QStyleOptionTabBarBase.

elideMode : Qt::TextElideMode

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:

Qt::TextElideMode elideMode() const
void setElideMode(Qt::TextElideMode)

See also QTabWidget::elideMode, usesScrollButtons, and QStyle::SH_TabBar_ElideMode.

expanding : bool

When expanding is true QTabBar will expand the tabs to use the empty space.

By default the value is true.

This property was introduced in Qt 4.5.

Access functions:

bool expanding() const
void setExpanding(bool enabled)

See also QTabWidget::documentMode.

iconSize : QSize

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:

QSize iconSize() const
void setIconSize(const QSize &size)

See also QTabWidget::iconSize.

movable : bool

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

By default, this property is false;

This property was introduced in Qt 4.5.

Access functions:

bool isMovable() const
void setMovable(bool movable)

selectionBehaviorOnRemove : SelectionBehavior

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.

This property was introduced in Qt 4.5.

Access functions:

SelectionBehavior selectionBehaviorOnRemove() const
void setSelectionBehaviorOnRemove(SelectionBehavior behavior)

See also removeTab().

shape : Shape

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:

tabsClosable : bool

This property holds 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.

This property was introduced in Qt 4.5.

Access functions:

bool tabsClosable() const
void setTabsClosable(bool closable)

See also setTabButton() and tabRemoved().

usesScrollButtons : bool

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:

bool usesScrollButtons() const
void setUsesScrollButtons(bool useButtons)

See also elideMode, QTabWidget::usesScrollButtons, and QStyle::SH_TabBar_PreferNoArrows.

Member Function Documentation

QTabBar::QTabBar(QWidget *parent = Q_NULLPTR)

Creates a new tab bar with the given parent.

QTabBar::~QTabBar()

Destroys the tab bar.

QString QTabBar::accessibleTabName(intindex) const

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

See also setAccessibleTabName().

int QTabBar::addTab(const QString &text)

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

Qt5 Virtual Slots

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

This is an overloaded function.

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

[virtual protected] void QTabBar::changeEvent(QEvent *event)

Reimplemented from QWidget::changeEvent().

[signal] void QTabBar::currentChanged(intindex)

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)

Note: Notifier signal for property currentIndex.

[virtual protected] bool QTabBar::event(QEvent *event)

Reimplemented from QObject::event().

[virtual protected] void QTabBar::hideEvent(QHideEvent *)

Reimplemented from QWidget::hideEvent().

[protected] void QTabBar::initStyleOption(QStyleOptionTab *option, inttabIndex) const

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.

See also QStyleOption::initFrom() and QTabWidget::initStyleOption().

int QTabBar::insertTab(intindex, 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(intindex, const QIcon &icon, const QString &text)

This is an overloaded 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.

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.

bool QTabBar::isTabEnabled(intindex) const

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

[virtual protected] void QTabBar::keyPressEvent(QKeyEvent *event)

Reimplemented from QWidget::keyPressEvent().

[virtual] QSize QTabBar::minimumSizeHint() const

Reimplemented from QWidget::minimumSizeHint().

[virtual protected] QSize QTabBar::minimumTabSizeHint(intindex) const

Returns the minimum tab size hint for the tab at position index.

This function was introduced in Qt 5.0.

[virtual protected] void QTabBar::mouseMoveEvent(QMouseEvent *event)

Reimplemented from QWidget::mouseMoveEvent().

[virtual protected] void QTabBar::mousePressEvent(QMouseEvent *event)

Reimplemented from QWidget::mousePressEvent().

[virtual protected] void QTabBar::mouseReleaseEvent(QMouseEvent *event)

Reimplemented from QWidget::mouseReleaseEvent().

void QTabBar::moveTab(intfrom, intto)

Moves the item at index position from to index position to.

This function was introduced in Qt 4.5.

See also tabMoved() and tabLayoutChange().

[virtual protected] void QTabBar::paintEvent(QPaintEvent *)

Reimplemented from QWidget::paintEvent().

void QTabBar::removeTab(intindex)

Removes the tab at position index.

See also SelectionBehavior.

[virtual protected] void QTabBar::resizeEvent(QResizeEvent *)

Reimplemented from QWidget::resizeEvent().

void QTabBar::setAccessibleTabName(intindex, const QString &name)

Sets the accessibleName of the tab at position index to name.

See also accessibleTabName().

void QTabBar::setTabButton(intindex, ButtonPositionposition, 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 0).

This function was introduced in Qt 4.5.

See also tabButton() and tabsClosable().

void QTabBar::setTabData(intindex, const QVariant &data)

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

See also tabData().

void QTabBar::setTabEnabled(intindex, boolenabled)

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

See also isTabEnabled().

void QTabBar::setTabIcon(intindex, const QIcon &icon)

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

See also tabIcon().

void QTabBar::setTabText(intindex, const QString &text)

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

See also tabText().

void QTabBar::setTabTextColor(intindex, const QColor &color)

Sets the color of the text in the tab with the given index to the specified color.

Qt virtual slot

If an invalid color is specified, the tab will use the QTabBar foreground role instead.

See also tabTextColor().

void QTabBar::setTabToolTip(intindex, const QString &tip)

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

See also tabToolTip().

void QTabBar::setTabWhatsThis(intindex, const QString &text)

Sets the What's This help text of the tab at position index to text.

Qt5 Virtual Slot

This function was introduced in Qt 4.1.

See also tabWhatsThis().

[virtual protected] void QTabBar::showEvent(QShowEvent *)

Reimplemented from QWidget::showEvent().

[virtual] QSize QTabBar::sizeHint() const

Reimplemented from QWidget::sizeHint().

int QTabBar::tabAt(const QPoint &position) const

Returns the index of the tab that covers position or -1 if no tab covers position;

This function was introduced in Qt 4.3.

[signal] void QTabBar::tabBarClicked(intindex)

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.

This function was introduced in Qt 5.2.

[signal] void QTabBar::tabBarDoubleClicked(intindex)

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.

This function was introduced in Qt 5.2.

QWidget *QTabBar::tabButton(intindex, ButtonPositionposition) const

Returns the widget set a tab index and position or 0 if one is not set.

See also setTabButton().

[signal] void QTabBar::tabCloseRequested(intindex)

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

This function was introduced in Qt 4.5.

See also setTabsClosable().

QVariant QTabBar::tabData(intindex) const

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

See also setTabData().

QIcon QTabBar::tabIcon(intindex) const

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

See also setTabIcon().

[virtual protected] void QTabBar::tabInserted(intindex)

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

See also tabRemoved().

[virtual protected] void QTabBar::tabLayoutChange()

This virtual handler is called whenever the tab layout changes.

See also tabRect().

[signal] void QTabBar::tabMoved(intfrom, intto)

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.

This function was introduced in Qt 4.5.

See also moveTab().

QRect QTabBar::tabRect(intindex) const

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

[virtual protected] void QTabBar::tabRemoved(intindex)

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

See also tabInserted().

[virtual protected] QSize QTabBar::tabSizeHint(intindex) const

Returns the size hint for the tab at position index.

QString QTabBar::tabText(intindex) const

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

See also setTabText().

QColor QTabBar::tabTextColor(intindex) const

Returns the text color of the tab with the given index, or a invalid color if index is out of range.

See also setTabTextColor().

QString QTabBar::tabToolTip(intindex) const

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

See also setTabToolTip().

QString QTabBar::tabWhatsThis(intindex) const

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().

[virtual protected] void QTabBar::timerEvent(QTimerEvent *event)

Reimplemented from QObject::timerEvent().

[virtual protected] void QTabBar::wheelEvent(QWheelEvent *event)

Reimplemented from QWidget::wheelEvent().

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.