tags:

views:

327

answers:

3

Hi folks,

How I can acquire access to QTabBar of QTabWidget ? Through searching in docs and internet, I've found only solution: subclassing QTabWidget, and in some way giving public access to QTabBar instance (QTabWidget::getTabBar() has "protected" access modifier). Is there any other solution ?

+3  A: 
tabBar->findChild<QTabBar *>(QLatin1String("qt_tabwidget_tabbar"));
atomice
It's looks like Qt has direct way to violating encapsulations principles, but acceptable in my case :) +1, if will no another answers I will accept this answer.
vnm
the only problem is...what if Qt decides to change the name of the tabbar object?
Evan Teran
AFAIK, names were defining in QtDesigner by developer (in case, when you create gui with designer)...
vnm
+1  A: 

What do you want to do to the tab bar?

May not help, but with stylesheets you can customise QTabWidget sub-controls ::tab and ::tab-bar.

Sam Dutton
I wan't to know QTabBar height at runtime. Anyway, thanks for you advice...
vnm
+3  A: 

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.

Evan Teran