Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] QDesktopWindow::availableGeometry not excluding taskbar (Qt 5.2, Windows 7)
I want my main window to have a maximized height but not necessarily a maximized width.
my code is:
QDesktopWidget *desktop = QApplication::desktop();
QRect desktopGeometry = desktop->availableGeometry();
int desktopHeight = desktopGeometry.height();
However, when running, the height is the full desktop, presumably availableGeometry isn't excluding the height of the taskbar (like it says that it will in the documentation). I'm using Qt 5.2 (edit). I'm running it on windows 7 (taskbar is not set to auto-hide).
Any idea why availableGeomerty isn't excluding the taskbar, or any other ideas to set the height (but not width) to fill the screen
Can you also add which version of Qt you are using ?
[quote author="SGaist" date="1399534117"]Hi,
Can you also add which version of Qt you are using ?[/quote]
Added. Using Qt 5.2.
hskoglund last edited by
Hi, actually availableGeometry() is excluding the taskbar, perhaps you're thinking of screenGeometry()?
Anyway, it's tricky when you call mainWindow.setFixedHeight(desktopHeight); because then you're only setting the client rect, then when Windows decorates your window with a title bar, minimize maximize etc. it gains additional height (on my Windows 7 32 pixels). And the taskbar is about the same pixel height :-)
Ah okay. Thanks. So do you know is there any way to set the height of the window, including title bar etc., to the available desktop height?
zeljko last edited by
I'm using qt-4.8.5 on win7 and availableGeometry() returns without taskbar size, but screenGeometry() returns complete size.So definitelly I have correct height.
What showMaximized() says ? Is it normal , or it's over taskbar ?
Because adding the frame added extra height to my window, the solution was to:
First call mainWindow.show(), when this is called windows adds the title bar and frame etc.
The height of all the added stuff can then be calculated by subtracting mainWindow.geometry.height() from mainWindow.frameGeometry.height().
Then the window can be resized to the height of the available screen geometry minus the calculated height of the frame etc.
int difference = mainWindow.frameGeometry.height() - mainWindow.geometry.height();
int height = QApplication::desktop().availableGeometry.height() - difference;