开发者

How can I insert a widget into a mainwindow generated by Qt designer?

开发者 https://www.devze.com 2022-12-08 17:41 出处:网络
I have a Main window build with Qt Designer and I also have a widget built with Qt designer (both in a separate ui file).How can I instantiate my 开发者_JAVA技巧widget into my mainwindow at runtime?Th

I have a Main window build with Qt Designer and I also have a widget built with Qt designer (both in a separate ui file). How can I instantiate my 开发者_JAVA技巧widget into my mainwindow at runtime?


The easiest way (using Designer) is to open your main window, drag a QWidget into it, and position/name the QWidget like you would your custom widget. Once that is done, right-click on the QWidget, and select Promote to.... A dialog will show up with the widgets it can be promoted to. At the bottom of that dialog, you can add a new widget for promotion. Type in the class name and include file information, and add that widget. Then select the entry in the list, and click the Promote button.

At the end of this process, you should be able to recompile, and your custom widget will be where you placed it in the main window.


Can't you use QMainWindow::setCentralWidget function?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号