Search code examples
qtsizeqmainwindow

Qt: Set size of QMainWindow


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.


Solution

  • 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);