QMainWindow::showMaximized() Doesn't Update Size

て烟熏妆下的殇ゞ 提交于 2019-12-12 20:26:32

问题


I'm trying to create a QMainWindow to encapsulate a QGraphicsView that I'm putting in it. I want it to start out maximized, so I do this:

QMainWindow *mainWindow = new QMainWindow();
mainWindow->setWindowState(Qt::WindowMaximized);
mainWindow->show();
qDebug() << mainWindow->size();

Which says my maximized window is 200x100, which is obviously incorrect.

Am I missing some sort of update function? I don't get why it wouldn't update the size. I've also tried using showMaximized() with the same result.

EDIT

My end-goal is to use the QMainWindow as a container for a QGraphicsView containing a QGraphicsScene. On top of all this, I want to have a QWebView at 50% width and 100% height, centered over everything.

So, I need the width and height in order to get all the coordinates and sizes correct.


回答1:


Well, the effect of setWindowState() is not immediate, it gets executed asynchronously. When the window state changes, the widget receives a changeEvent(), so you should reimplement this or resizeEvent() to get the width() and height() after the maximization takes place.



来源:https://stackoverflow.com/questions/16552495/qmainwindowshowmaximized-doesnt-update-size

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