K. Barresi
K. Barresi

Reputation: 1315

QMainWindow::showMaximized() Doesn't Update Size

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.

Upvotes: 4

Views: 6376

Answers (1)

vMTom
vMTom

Reputation: 21

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.

Upvotes: 2

Related Questions