Qt4: Placing QMainWindow instance inside other QWidget/QMainWindow

扶醉桌前 提交于 2019-11-30 20:35:23

Having the same problem, I found the solution here.

QMainWindow sets its window type to Qt::Window so that it will be in an independent window even if it has a parent (you can confirm this by calling show() on your QMainWindow, and you will see it in its own window). Try adding the line

window->setWindowFlags(Qt::Widget);

after you construct the QMainWindow.

centralwidget = new QMainWindow(this);
centralwidget->setWindowFlags(Qt::Widget);
setCentralWidget(centralwidget);

This should help.

QMainWindow provides predefined stuff like toolbars and status bars and menu bars in a platform agnostic way (it "does the right thing", without manual intervention). If all you need is a bunch of buttons in a layout, use QWidget.

You need to make sure each QMainWindow has centralQWidget`, other than that, you should be fine.

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