Qt - How to create a window with multiple tabs?

I want to create a single-window application with two tabs. How can I set two tabs in a window and click to switch, just like a browser window and tabs?

PS: Two tabs have a different layout of buttons and text widgets and functions in different ways.

+6
source share
1 answer

http://doc.qt.io/qt-5/qtabwidget.html#details

The QTabWidget class provides a stack of tabbed widgets.

The tab widget provides a tab bar (see QTabBar ) and a "page area" that is used to display the pages associated with each tab. By default, the tab bar is displayed above the page area but with different configurations (see TabPosition ). Each tab is associated with a different widget (called a page). The page displays only the current page area; all other pages are hidden. The user can show another by clicking on a tab or by pressing the key combination "Alt +" if he has one.

The usual way to use QTabWidget is as follows:

  • Create a QTabWidget .
  • Create a QWidget for each of the pages in the tab dialog box, but do not specify parent widgets for them.
  • Insert child widgets into the page widget, using layouts to arrange them normally.
  • Call addTab() or insertTab() to place the page widgets in the tab widget, providing each tab with a suitable label with an additional keyboard shortcut.

The position of the tabs is determined by TabPosition , their form is tabShape .

...

And there is your answer.

EDIT: link to an example too.

http://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html

Hope this helps.

+11
source

Source: https://habr.com/ru/post/945641/


All Articles