You should not put your code in the QTabBar c'tor. You should re-implement, that is override a virtual method, the size hint function.

You're then supposed to inherit the QTabWidget from which you use your QTabBar.

Then, your code uses your tab widget instead of QTabWidget.