[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();
mainWindow.setFixedHeight(desktopHeight);
@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
-
Hi,
Can you also add which version of Qt you are using ?
-
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 :-)
-
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.
example:
@
mainWindow.show();
int difference = mainWindow.frameGeometry.height() - mainWindow.geometry.height();
int height = QApplication::desktop().availableGeometry.height() - difference;
mainWindow.setFixedHeight(height);
@