Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Rendering to physical sizes, how to let it work on all platforms?

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
pysicalscalingdpidpi awarenessppi
4 Posts 3 Posters 1.6k 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.
  • R Offline
    R Offline
    RaDq1
    wrote on 8 May 2017, 16:39 last edited by
    #1

    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
    0
    • J Offline
      J Offline
      johngod
      wrote on 8 May 2017, 17:18 last edited by
      #2

      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 9 May 2017, 11:06
      0
      • L Offline
        L Offline
        Lorenz
        wrote on 9 May 2017, 10:45 last edited by
        #3

        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
        0
        • J johngod
          8 May 2017, 17:18

          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 Offline
          R Offline
          RaDq1
          wrote on 9 May 2017, 11:06 last edited by
          #4

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

          2/4

          8 May 2017, 17:18

          • Login

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