Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detect changing devicePixelRatio
QtWS25 Last Chance

Detect changing devicePixelRatio

Scheduled Pinned Locked Moved General and Desktop
retinadevicepixelrati
7 Posts 5 Posters 9.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mooshx
    wrote on last edited by mooshx
    #1

    Howdy! We have an app where the main window contains a QGLWidget among other widgets. When the main window is dragged between monitors, one "normal" and one retina, at a certain point the UI "snaps" to either use the retina resolution or normal resolution. Is there a way to reliably detect when the display resolution changes (from the main window's perspective)? After failing to find a signal or other virtual function that does so we tried overriding the bool event(QEvent*) method. In that method we keep track of the devicePixelRatio() value. When it changes we emit a signal. This turns out to work only some of the time. We've found that even if the window never travels to the retina monitor the value reported by devicePixelRatio() is sometimes 2, and sometimes 1. Ideally Qt already has a better way to detect this scenario.

    In case it comes up I'll say in advance we can't simply change over to use QOpenGLWidget. We're stuck using QGLWidget for the time being under Qt 5.3.1 (Mac/Windows). Thanks in advance for any suggestions.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I guess you're on X11?

      M 1 Reply Last reply
      0
      • ? A Former User

        I guess you're on X11?

        M Offline
        M Offline
        mooshx
        wrote on last edited by
        #3

        @Wieland Sorry, should have mentioned in original post. This is for Mac/Windows

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dyami Caliri
          wrote on last edited by
          #4

          You can connect to the screenChanged(QScreen)* signal of the QWindow to which your widget belongs.

          After the window is set up:
          connect(window()->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged()));

          Where screenChanged() is a slot you define to check devicePixelRatio().

          The window changes screens when the majority of it is in the new screen.

          ? F 2 Replies Last reply
          2
          • D Dyami Caliri

            You can connect to the screenChanged(QScreen)* signal of the QWindow to which your widget belongs.

            After the window is set up:
            connect(window()->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged()));

            Where screenChanged() is a slot you define to check devicePixelRatio().

            The window changes screens when the majority of it is in the new screen.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @Dyami-Caliri This is not my thread, but: Thanks Dyami Caliri! Didn't knew screenChanged() exists :-)

            1 Reply Last reply
            0
            • D Dyami Caliri

              You can connect to the screenChanged(QScreen)* signal of the QWindow to which your widget belongs.

              After the window is set up:
              connect(window()->windowHandle(), SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged()));

              Where screenChanged() is a slot you define to check devicePixelRatio().

              The window changes screens when the majority of it is in the new screen.

              F Offline
              F Offline
              fxxxx
              wrote on last edited by
              #6

              @Dyami-Caliri, thanks! It works fine when I drag my window between two monitors. However, when I relocate the menu bar to switch to the other monitor(System Preferences -> Displays -> Arrangement on Mac), it seems that screenChanged(QScreen*) signal didn't emit. Is this situation an exception? Or should I listen to another signal?
              Thanks a lot.

              I 1 Reply Last reply
              0
              • F fxxxx

                @Dyami-Caliri, thanks! It works fine when I drag my window between two monitors. However, when I relocate the menu bar to switch to the other monitor(System Preferences -> Displays -> Arrangement on Mac), it seems that screenChanged(QScreen*) signal didn't emit. Is this situation an exception? Or should I listen to another signal?
                Thanks a lot.

                I Offline
                I Offline
                intelegenter1
                wrote on last edited by intelegenter1
                #7

                @fxxxx you should set attribute for your main window: setAttribute(Qt::WA_NativeWindow); but it causes optimization problems, because it is legacy feature. anyway, it will solve your problem, and windowHandle() should return valid pointer, and will emit signal screenChanged().

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved