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

QWidget::screen() isn't returning the correct QScreen after a monitor disconnect/reconnect



    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15
    • Fix Version/s: None
    • Component/s: GUI: High-DPI
    • Labels:
    • Platform/s:


      QScreen from QMainWindow isn't correct after the WM_DPICHANGED message.
      As a result the application is displaying at the incorrect DPI.

      User Config:
      Two monitors.
      MonitorA: 1920x1080 at 100% DIP (Main)
      MonitorB: 1920x1080 at 125% DIP

      MonitorA & MonitorB are connected with the application running on MonitorA.
      User then disconnects MonitorA, the application is auto moved to MonitorB, so MonitorB is now the main.
      User reconnects MonitorA, the application is moved back to MonitorA but the DPI isn't updated.

      The issue is that QMainWindow is still using the QScreen from MonitorB and never updated to the QScreen for MonitorA, testapp, screenshots and message log attached.

      Debugging info:
      From debugging this, the issues appears to be that Qt is ignoring the WM_DPICHANGED messages, this is because Qt will ignore all calls to the method "QWindowsWindow::checkForScreenChanged" if "QWindowsScreenManager::isSingleScreen()" is true.

      The second screen is only added when Qt gets the message WM_SETTINGCHANGE, and by that time we already missed the WM_DPICHANGED messages.

      It looks like Qt should be adding the second screen on the WM_DISPLAYCHANGE message, but in the method "QWindowsScreenManager::handleDisplayChange" Qt will only checks if the resolution has changed, and in this case the resolution is the same on the two monitors.

      Drag the the app across to the other monitor and back, the DPI will be updated on the WM_DPICHANGED message as Qt now knows about the second monitor.

      From testing with just a Qt test app the application will fix it's self on move/resize, but if Qt::FramelessWindowHint is set, the only option is to restart the app.


        1. DisplayTesting.7z
          4 kB
          Chris O'Gorman
        2. Expected.PNG
          19 kB
          Chris O'Gorman
        3. issue.txt
          11 kB
          Chris O'Gorman
        4. ResultBug.png
          11 kB
          Chris O'Gorman
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            sorvig Morten Sørvig
            chrisog Chris O'Gorman
            PM Owner:
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            1 Vote for this issue
            2 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes