Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
5.11.2, 5.12.2
-
None
Description
Hello,
I can't properly restore the position of my main window on Windows.
I have 3 monitors, 2 with 3840x2160 with no scaling, they are set to100%.
1 is the 'user' environment monitor with 3840x2160 with 150% scaling.
This is the one you see in the screenshots.
The combination of saveGeometry and restoreGeometry works on the 100% displays, but on the 150% display, restoreGeometry restores the window far too large.
The saved dimensions seems not to be the problem, when I saved the size and position by my own ( which is difficult to get the proper topLeft ), restore the position works quite well, but the 'resize' of the window show the same wrong result as restoreGeometry.
We have set our application to use HighDpi in the main.cpp before everything else.
QCoreApplication::setAttribute( Qt::AA_EnableHighDpiScaling ); QCoreApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
I we don't use Qt::AA_EnableHighDpiScaling, the restore works, but this is not an option for us.
>> The Problem <<
- The main monitor ( screeen ) is at 100%, no scaling.
This is typically the one where the application mainwindow opens.
I call this screen the SCREEN1 - The application was moved to the monitor with 150% scaling.
This is the SCREEN2.
When the user closes the app, saveGeometry properly saves the position etc.
Evething is fine so far.
- The user opens the application again
The mainwindows opens on SCREEN1.
I'm trying to restore the mainwindow's position:
- restoreGeometry sets the position and size with the saved values.
The mainwindow is now located on SCREEN2. - something in the Qt's code detects the screen change ( ?? ) and calls the function
void QWindow::setGeometry(const QRect &rect)
which will then modify the window size:
if (newScreen && isTopLevel())
nativeRect = QHighDpi::toNativePixels(rect, newScreen);
Because the screen has a different scaling, the size is changed here.
This is the problem!
With this knowlegde I found an ugly workarround:
Move the mainwindow to the saved screen and call restoreGeometry afterwards...
Have fun,
Alex