Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the QTabBar instance

Tags:

c++

qt

qt4

How can I get access to the QTabBar of a QTabWidget?

The only solution I've found is to subclass QTabWidget and override the protected QTabWidget::getTabBar() as public. Is there any other way of doing this?

like image 762
cybevnm Avatar asked Dec 07 '25 08:12

cybevnm


2 Answers

tabBar->findChild<QTabBar *>(QLatin1String("qt_tabwidget_tabbar"));
like image 72
atomice Avatar answered Dec 09 '25 20:12

atomice


As you mentioned, subclassing is the proper solution since it is protected. Something like this:

class TabWidget : public QTabWidget {
public:
    TabWidget(QWidget *p = 0) : QTabWidget(p){}

public:
    QTabBar *tabBar() const { return QTabWidget::tabBar(); }
};

You can tell designer to "promote" your QTabWiget to a TabWidget then you will have an accessible tabBar() function.

like image 44
Evan Teran Avatar answered Dec 09 '25 22:12

Evan Teran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!