How can I insert a widget into mainwindow created by Qt?

I have a main window assembly with Qt Designer, and I also have a widget built with a Qt designer (both in a separate ui file). How can I instantiate my widget in my main window at runtime?

+3
source share
2 answers

The easiest way (using the constructor) is to open the main window, drag it into it QWidgetand place / name QWidgetin the same way as your custom widget. Once this is done, right-click on QWidgetand select the Promote ... . A dialog box appears with widgets that you can promote. At the bottom of this dialog box, you can add a new widget for promotion. Enter the class name and provide information about the file and add this widget. Then select an entry in the list and click the Promote button .

At the end of this process, you can recompile and your custom widget will be placed in the main window.

+6
source

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


All Articles