lleviy
lleviy

Reputation: 436

How to insert form.ui into mainwindow.ui in Qt?

I placed into the mainwindow QTabWidget with some content. But mainwindow is overloaded, so I decided to put the logic of the elements in each tab into a separate class, i.e. 6 more files appears in my project:

MyTabWidget1.h
MyTabWidget1.cpp
MyTabWidget1.ui

MyTabWidget2.h
MyTabWidget2.cpp
MyTabWidget2.ui

Now I want the contents of the tabs to appear in the main window's Tab Widget. How can I do it?

Upvotes: 1

Views: 826

Answers (1)

Zlatomir
Zlatomir

Reputation: 7034

You have 2 options to compose widgets:

1) In Designer mode of Creator using the promote widget functionality. Add the pages into the tab-widget in designer, make sure you select each page individually not the QTabWidget (you can do that in the object browser, each page will be a child of the QTabWidget) select Promote to... in the context menu for each individual page and enter the corresponding class name and header filenames in the dialog that opens.

2) using C++ code you can access the tab widget inside main window class and use addTab

//in the constructor of mainwindow you can do something like this:
ui->TABWIDGET->addTab(new MyTabWidget1(), "First tab");
ui->TABWIDGET->addTab(new MyTabWidget2(), "Second tab");
//replace TABWIDGET with the corresponding name you used for your tab widget in the mainwindow.ui

Upvotes: 2

Related Questions