PyQt4: Set size of the tab bar in QTabWidget

2019-08-31 16:51发布

问题:

How would you change the height of the tab bar in a QTabWidget?

回答1:

You should create a customized QTabBar and overwrite its tabSizeHint method. Then set that customised QTabBar as the bar of your QTabWidget using the QTabWidget.setTabBar method.

I think the following (non tested) code could help you:

class TabBar(QTabBar):

   def tabSizeHint(self, index):
       width = QTabBar.tabSizeHint(self, index).width()
       return QSize(width, your_wanted_height)

You can find other customization examples here.