Priority: P2: Important
Affects Version/s: 5.14, 5.15
Fix Version/s: None
Component/s: GUI: High-DPI
For systray applications with widgets created in a hidden state the following scenario might be of relevance: When changing the primary display's resolution before any of the created widgets are shown, QGuiApplication does not update the primary QScreen's data. So when the first widget shows up, and the resolution was changed after the creation of QApplication and before the first show event, QGuiApplication::primaryScreen() has the wrong display data even after the following show events. The only way to update QGuiApplication::primaryScreen() is to change the primary display's resolution after the first show event.
In that scenario for getting the primary screen's data the following calls are used:
Versions Qt 5.14.0, 5.15.0 and 5.15.1 are affected by the problem.
The testcase project is contained in the attached zip file:
- Create the project with cmake from the attached example zip file (tested configuration: generator of project: Visual Studio 14 2015, Optional platform for generator: x64, select option 'Use default native compilers', Qt5_DIR: cmake/qt5 of Qt 5.15.1)
- Compile project (if Visual Studio was configured as the generator: open qt_resolution.sln, build the whole solution, set qt_resolution as the startup project, copy qt dlls and plugin/platforms folder into the bin directory manually)
- Set the display resolution to a size A with smaller than native height for the system before starting the executables (example: primary screen has native resolution B = 1920x1080, set resolution A = 1366x768 for the system)
- Start the executable ./bin/qt_resolution. A System Tray Icon with a green dot for its icon appears. Don't click on it yet, if any widget (including the tray icon's menu) opens now, the testcase won't work.
- Set the resolution to native size B for the system (example: go from resolution A = 1366x768 to native resolution B = 1920x1080)
- Open the System Tray Icon's menu by right clicking on it. A menu with actions 'Show Notifications' and 'Exit' opens. Click on menu point 'Show Notifications'.
- A borderless widget with title 'Notifications' and text 'Display data' opens. Under 'Display data' the properties of the primary screen are displayed. They are refreshed each time the 'Notifications' widget opens by calling QGuiApplication::sync() and then QGuiApplication::primaryScreen().
- Observe that below 'Display data' right from 'size' resolution A instead of the currently set resolution B is shown. Apart from that the 'Notifications' widget is positioned in the middle of the screen, but it is supposed to touch the top, bottom and right of the primary screen with its top, bottom and right.
- Close the 'Notifications' widget with the ToolButton 'Close' on the top right of the widget. Set Resolution A, and then Resolution B.
- Open the 'Show Notifications' widget like in point 6. Observe that right from 'size' the correct resolution B is displayed. The 'Notifications' widget is now correctly positioned such that it touches the top, bottom and right of the primary screen with its top, bottom and right.
For details of the platform see
- Qt 15.5.1, x64
- MS Visual Studio Professional 2015 (Version 14, Update 3)
- Cmake 3.14.3
- Windows 10 x64 (Version 2009)