Important: Please read the Qt Code of Conduct -

[SOLVED] Get the availableGeometry of monitor WITH the taskbar on Windows

  • While in the showMaximized mode, I'm trying to set a background image to my mainwindow by obtaining the size of the screen using

    QRect rect = desktopWidget->availableGeometry();

    But this returns the size of the screen excluding the taskbar. I read in the documentation that if int screen = -1 then the whole screen would be considered. Where do I specify the parameter? I tried

    QRect rect = desktopWidget->availableGeometry(int screen = -1);


    int screen = -1;
    QRect rect = desktopWidget->availableGeometry(screen);

    But I suppose the above two methods are syntactically wrong. Could someone please help me in this regard?

  • If you're using Qt 5 you could use the QScreen class ( QScreen::geometry ).

  • Yes, according to the documentation that method should indeed return the full resolution of the display. Having the parameter "= -1" simply sets a "default" value to call the method without any parameter and use -1.

    Keeping in mind 99.99% of the screens out there are with standard resolutions or aspect ratios, you could easily calculate the actual size.

  • P.S. using availableGeometry with -1 won't help. -1 is the screen no.
    You could also try to use QDesktopWidget::screenGeometry instead

  • Thank you, vidar. Yes, I'm using Qt 5 and using screenGeometry helped achieve what I was trying to do. Thank you so much.

Log in to reply