Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Detect changing devicePixelRatio

    General and Desktop
    retina devicepixelrati
    4
    6
    7708
    Loading More Posts
    • 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
      mooshx last edited by mooshx

      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 Reply Quote 0
      • ?
        A Former User last edited by

        I guess you're on X11?

        M 1 Reply Last reply Reply Quote 0
        • M
          mooshx @Guest last edited by

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

          1 Reply Last reply Reply Quote 0
          • D
            Dyami Caliri last edited by

            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 Reply Quote 2
            • ?
              A Former User @Dyami Caliri last edited by

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

              1 Reply Last reply Reply Quote 0
              • F
                fxxxx @Dyami Caliri last edited by

                @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.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post