Qt: Set size of QMainWindow

dadod2 picture dadod2 · Apr 29, 2013 · Viewed 76.9k times · Source

I'm new to Qt, so I wonder whether there is a way to set the size of a QMainWindow to (for example) 70% of the user's desktop.
I tried the stretch factor but it didn't work. QWidget::setFixedSize worked but only with a pixel number, I think.

Answer

muesli picture muesli · Nov 4, 2014

Somewhere in your QMainWindow constructor, do this:

resize(QDesktopWidget().availableGeometry(this).size() * 0.7);

This will resize the window to 70% of the available screen space.