How can I make two rows of tabs in Qt

2019-08-31 06:03发布

问题:

I would like to have something like the following image. I want two rows of tabs. One is included in the other. Is using two QTabWidget the way to go? Also, I would like to mention that the program's main window will display this structure. If you have any suggestions...

I would like the tabs to look like the following (of course, not exactly; this handmade image is awful).

Image http://imageshack.us/a/img831/3889/subtabs.png

回答1:

Use nested QTabWidgets: an outer primary tab which contains its own secondary QTabWidget (where one is necessary).


Since you are after specific look, then there are three possible solutions (ordered by complexity) :

  1. See what you can do with Qt style sheets using nested QTabWidgets. See this answer for some example code, and of course reference in docs.

  2. Forget QTabWidget, write your own, containing custom tab bar, and using a QStackedWidget or just nested QStackedLayout for tab contents. You can nest these custom tabbed widgets like you would with QTabWidget, or just have dynamic two-row tab bar in one non-nested custom tab widget, it's your code now.

  3. Start using QML for UI, perhaps just for a custom tab bar, perhaps for the whole central widget, depending on what you have there.



回答2:

You can use QTabBar instead. A QTabWidget is formed from a QStackedWidget and a QTabBar, but you can use QTabBars directly - and have two or three or more layers of tabs.