Replace current QWidget to another QWidget in QMainWindow

浪尽此生 提交于 2019-12-24 15:25:53

问题


I have some QWidget class which ui files are separate from QMainWindow ui file.

how to add or replace current QWidet which is glued to QMainWindow into other QWidget from different class and ui files on the same QMainWindow ?


回答1:


If I understand you correctly, you are currently displaying one widget and upon an action, you want to hide that widget and display another one in its place.

If this is correct, you might want to look at QStackedLayout.




回答2:


Add your widget headers (note that you have to generate the headers from ui and inherit) into promoted widgets in your QMainWindow.ui.

Then, You just have to insert a QWidget,QFrame, ... depending on the base class of your widget, and right click on it and select your custom widget from Promote to.. Submenu.

Heres a link to QT manual



来源:https://stackoverflow.com/questions/15870739/replace-current-qwidget-to-another-qwidget-in-qmainwindow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!