[Solved] How can I change the app resolution

  • Hi!

    I'm making a new GUI app and I want it to show up with a especific resolution, so when in main.cpp I say w.show() it runs in 550x300. I've tried w.resize() but it just shows a little part of the screen instead of change its resolution so if I put an element like this:


    QRect rec = QApplication::desktop()->screenGeometry();
    int h= rec.height()/8;
    int w= rec.width();

    button->setMinimumSize(w,h); //this button will fit inside the screen with full width


    with the resize I just see a part of the button and I should see it complety.


  • Moderators

    First of all it's not resolution. It's simply size. Resolution is the physical granularity of your display.

    QRect rec = QApplication::desktop()->screenGeometry();
    First of all you should not use that. It doesn't take into account any taskbars or other user specific settings. If anything you should use availableGeometry() instead of screenGeometry(), which gives you the working area on the given screen. Anyway this also doesn't handle well multi-monitor setups, which are very common these days.

    Another thing is do you want the whole window (with the frame) to have specific size or just the client area (the part where widget is drawn)?

    As for the above calculation - if height/8 is, say, 400 and the window size is fixed at 300 then of course it will cut some of it.

    I would suggest to only fix the size of the window with "setFixedSize":http://doc.qt.io/qt-5/qwidget.html#setFixedSize and then use layouts inside to place your widgets (buttons, labels etc.).

  • Hi,
    avaibleGeometry() didnt work, just did the same as screenGeometry. So I had to fix is with setFixedSize(),

    thank you.

Log in to reply