c++qtqt-designerqtabwidget

How to make the tabs of QTabWidget fit the size of the container


Say I have a tab-widget which is 5 inches wide. Now when I add tabs to it, then each tab is 1 inch wide. How can I make the tabs occupy equal length space in the widget, such that each tab is 2.5 inches wide ? I am using Qt Designer - is there a property that I can set?


Solution

  • The good news is that QTabBar has a property that does almost exactly what you want, namely setExpanding.

    The bad news is that QTabWidget effectively ignores that property, because it always forces its tabs to be the minimum size (even if you set your own tab-bar).

    The best workaround would appear to be to create your own TabWidget class based on a QTabBar and a QStackedLayout. But note that this still may not expand the tabs to the fill all the available space. When I tried it, two tabs only expanded to fill two-thirds of the space - so it looks like it may always leave room for one tab at the end if it can.