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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • None
    • 5.15
    • GUI: High-DPI
    • None
    • Windows

    Description

      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% DPI (Main)
      MonitorB: 1920x1080 at 125% DPI

      Steps:
      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.

      Workaround:
      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.
       

      Attachments

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

        Activity

          People

            sorvig Morten Sørvig
            chrisog Chris O'Gorman
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes