Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-119851

Incorrect size for Window on display change



    • Windows


      I've been trying to get to the bottom of a bug we encountered when a user un-plugs a monitor, forcing the main window to move to the other screen.



      Basic test application with a QMainWindow
      Windows 11

      2 Monitors

      Primary monitor ("Make this my main display" is ticked)
      Resolution: 1920x1080
      DPI: 150%

      Secondary Monitor
      Resolution: 3840x2160
      DPI: 100%

      Reproducible steps:

      • Maximize your test application on the secondary monitor.
      • Make sure it is active/has focus.
      • Unplug the secondary monitor.


      The Window will move to the other screen, the elements will scale to the correct DPI.

      But the window size is incorrect.


      The root cause is that the WM_DPICHANGED events and windows geometry events always arrive before the WM_DISPLAYCHANGE.

      The geometry is set using the old monitors DPI as QWindowsWindow::checkForScreenChanged() 
      fails inside QWindowsWindow::handleDpiChanged() or QWindowsWindow::handleGeometryChange()
      It cannot find the new monitor, as again WM_DISPLAYCHANGE has not arrived and there are two old monitors in the list at this point.
      Once WM_DISPLAYCHANGE arrives, qt updates the correct screen of the window and its elements scale correctly.

      But the geometry has not changed at this point, and no resizing of the actual window will occur. (unless manually done so)

      I believe I have a fix and would like to open a PR, but first would like track the issue here


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            sorvig Morten Sørvig
            ctummon Cathal Tummon
            1 Vote for this issue
            7 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes