问题
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