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

[macOS] Incorrect qApp->primaryScreen()->geometry() after resizing/scaling the screen in System Display Prefs on Mojave

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • None
    • 5.12.5, 5.13.1, 5.14.0 Beta2
    • macOS Mojave 10.14.6 on a MacBook Pro 2019
      Qt 5.13.1 (also tried latest 5.14.0-beta2)
    • macOS
    • dcbe25bbbb603bc335d7cf0982a80293289b0d8f

    Description

      Hi guys,

       

      I had a weird issue in my app and I finally tracked it down to what I believe is a bug/inconsistency in Qt:  

       

      How to reproduce:

       

      1. Start your Qt based GUI app.

      2. User changes the screen resolution of primary display via system preferences panel on macOS

      3. App's list of QScreens now have the old geometry and never learn about the new screen resolution. The QScreen no longer agrees with what the Cocoa NSScreen.screens returns(Cocoa is right, Qt's QScreens are wrong and have the old geometry).

       

      I did some digging and basically if macOS sends your app a display

      kCGDisplayDesktopShapeChangedFlag

       "Shape Changed" callback (which can happen as the result of the user reconfiguring the screen's resolution in the control panel [see screenshot]), it appears Qt's QScreens still have the old "shape" (geometry)

       

      If you query the geometry of the QScreen classes returned from qApp->screens() or qApp->primaryScreen(), you get the old geometry.  The only way to fix this is to quit the app and restart it and then it picks up the new geometry... but should the user decide to change screen resolution again on the primary screen - Qt won't get the new geometry for the qscreen.

       

      This affects some of my code that relies on the QScreen geometry for decisions it makes.

       

      For example:

       

      1. Start the app in 1400x900 
      2. Go to System Preferences -> Displays -> Change the display resolution (they call it scaling, but it's really a logical resolution change).
      3. Application gets the event, Qt windows draw ok, etc
      4. However, if your app queries the QScreens, they all have the old geometry. This list of screens disagrees now with what Cocoa's NSScreen.screens returnes.

       

      I have attached a log from the debug console in my app.  It basically illustrates how Cocoa has a list of screens and they are correct, and Qt still has the old screens.

       

      Attachments

        Activity

          People

            vestbo Tor Arne Vestbø
            cculianu calin culianu
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: