Qt: Set size of QMainWindow
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.
You can use the availableGeometry(QWidget*)
method in QDesktopWidget
, this will give you the geometry of the screen that this widget is currently on.
For example:
QRect screenSize = desktop.availableGeometry(this);
this->setFixedSize(QSize(screenSize.width * 0.7f, screenSize.height * 0.7f));
Where this
is the MainWindow pointer.
This will work when using multiple screens.
Thanks to Amir eas. The problem is solved. Here's the code for it:
#include <QDesktopWidget>
#include <QMainWindow>
...
QDesktopWidget dw;
MainWindow w;
...
int x=dw.width()*0.7;
int y=dw.height()*0.7;
w.setFixedSize(x,y);