Qt Forum

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

    Solved Rendering to physical sizes, how to let it work on all platforms?

    QML and Qt Quick
    pysical scaling dpi dpi awareness ppi
    3
    4
    1080
    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.
    • R
      RaDq1 last edited by

      I'm creating an application that should render things to physical sizes, i.e. an intermediate goal would be to render a square that is 4x3 cm on all displays (using both iOS & windows).

      (I understand that its not really possible to do this always correct as the real world size of screens varies)

      the problem I ran into today is that on iOS there is a 2x factor which I can't identify by using generic calls.
      QGuiApplication::primaryScreen()->devicePixelRatio()
      returns 1 on a iPad (incorrect? - iOS 9.3) and 2 on a iPhone (correct? - also iOS 9.3)
      or am i missing something?

      using a QQuickPaintedItem derived class in the paint(QPainter *painter) function:

      auto physicalpixelsperinch = painter->device->physicalDpiX() * QGuiApplication::primaryScreen()->devicePixelRatio();
      

      is (more or less) correct for windows and a iPhone, but not for an iPad.
      what I am I missing here?

      1 Reply Last reply Reply Quote 0
      • johngod
        johngod last edited by

        Hi
        On Desktop and Android, something like this should work:

        import QtQuick.Window 2.2
        
        Rectangle {
            property real mm: Screen.pixelDensity
        
            width: 40*mm
            height: 30*mm
        }
        

        The problem is that, on Android, depending on the devices, the hardware vendors dont supply reliable firmware, and usually Screen.pixelDensity doesnt give acurate values. On desktop, I usualy get correct values. Not sure abou t IOS, but please check it and let me know :)

        R 1 Reply Last reply Reply Quote 0
        • Lorenz
          Lorenz last edited by

          You could check out the pixelToInches function that is included in the V-Play SDK.

          Developer @ V-Play Engine - http://v-play.net/qt

          V-Play simplifies

          • Game Development with Qt
          • Mobile App Dev with Qt esp. iOS & Android

          What others say
          V-Play scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

          1 Reply Last reply Reply Quote 0
          • R
            RaDq1 @johngod last edited by

            @johngod Thank you so much, you're right Screen.pixelDensity would be the complete solution if it was in qml,
            sifting trough the qt source i was able that it was derived from:

            double pixelpermm = QGuiApplication::primaryScreen()->physicalDotsPerInch() / 25.4
            //physicalDotsPerInchX() & physicalDotsPerInchY() also exist
            

            and it seems to be correct on both my iPhone & iPad quite wel (better than all other ways I found so far)

            @Lorenz thanks, but for the time being I want to stick to Qt as it is a paid sdk as soon as you go commercial

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