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

Wrong pixel ratio when using OpenGL in an embedded window context



    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 6.0.0, 6.1.0
    • Fix Version/s: 6.1.1, 6.2.0 Alpha
    • Component/s: GUI: High-DPI, GUI: OpenGL
    • Labels:
    • Environment:
      macOS 10.15, macOS 11.0
      XCode 12.5
      Qt 6.0 and Qt 6.1
    • Platform/s:
    • Commits:
      40878e75176880e95398604d9e63be2138cc642b (qt/qtbase/dev) 4e58b19b0c1d3d46808b5cc42e147ac7da8a7e21 (qt/qtbase/6.1)


      I'm having an issue with Qt 6.0 and Qt 6.1 which doesn't happen with Qt 5.15 and earlier.

      On a Retina screen, when I embed a Qt window inside a non-Qt host app AND uses QOpenGLWidget, my Qt window is rendered with a device pixel ratio of 1 (instead of 2), while the non-Qt host app around it is still rendered at full Retina resolution (device pixel ratio of 2).

      I've rooted down the issue to this commit : https://github.com/qt/qtbase/commit/1fc7ca091b3fdda52381a383318a3a752ec21132

      My interpretation is that while standalone Qt applications are fine with this commit, Qt app embedded within other host apps still need to account for different environments.

      And indeed if I apply the reverse of this commit to Qt 6.1.0, I get back the full Retina resolution on my embedded Qt app which uses OpenGL.

      In addition to that I had to make two slight changes to this reverse commit :

      in qtbase/src/plugins/platforms/cocoa/qnsview_drawing.mm I had to force 

      - (BOOL)layerEnabledByMacOS

      to always return true (which is safe because 10.14 is now the minimum Qt requirement), because otherwise it could be mislead by a host app built with an older macOS SDK (which doesn't matter in this case, as it's my Qt app SDK that matters). Wrongly returning "false" in this case led to a freeze of the embedded Qt app when trying to display new windows.

      And although it was never called in my case, I also made the same change to qtbase/src/plugins/platforms/cocoa/qcocoaintegration.mm in 

      bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) const


      case ThreadedOpenGL:

      should always return false.

      With this reverse commits+2 slights changes I have my OpenGL Qt app running fine both in standalone and embedded mode, on Mojave, Catalina and Big Sur.


      For the sake of clarity I'm attaching the modified files:
      6.1.0 -> reverse commit (8 files) -> slight modification in qnsview_drawing.mm and qcocoaintegration.mm


        1. qcocoabackingstore.h
          5 kB
        2. qcocoabackingstore.mm
          34 kB
        3. qcocoaglcontext.h
          4 kB
        4. qcocoaglcontext.mm
          22 kB
        5. qcocoaintegration.mm
          17 kB
        6. qcocoawindow.h
          11 kB
        7. qcocoawindow.mm
          71 kB
        8. qnsview_drawing.mm
          11 kB
        For Gerrit Dashboard: QTBUG-93770
        # Subject Branch Project Status CR V



            vestbo Tor Arne Vestbø
            divide Robin Lobel
            0 Vote for this issue
            3 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes