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. Scalability on different screens resolution, wrong DPI

Scalability on different screens resolution, wrong DPI

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
scalingresolutiondevicesscreen
3 Posts 3 Posters 2.1k 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.
  • A Offline
    A Offline
    AllanE
    wrote on 8 Mar 2016, 16:32 last edited by AllanE 3 Aug 2016, 16:33
    #1

    Hello everyone,

    I am new to Qt Quick but learning fast :)

    I am currently developing an app that will target Android & iOS.

    I have been facing an issue due to the fact that all Android devices does not share the same screen size nor the same DPI.

    I want my graphical items to have the same size (and by that I mean the REAL size, if I take a ruler I want the measure to be the same) on all of my devices.

    So far, I've established a semi working algorithm that will allow me to achieve that.

    //Calculate the DPI of the device
    property real dpi: Screen.pixelDensity*25.4
    
    [...]
    
    Rectangle {
            width: 4 * dpi  // Should be 4 inches on any screen
            height: 2 * dpi; // Should be 2 inches on any screen
            anchors.centerIn: parent
            color: "red"
     }
    

    The thing is, that this doesn't work on all of my devices. When I'm looking at the value of the DPI on my different devices, it is not always correct.

    Galaxy S5: 479 (should be 432)
    Nexus 9: 288 (correct DPI)
    Nexus 10: 298 ( real DPI is 300, but close enough)

    I don't have more devices to test with, but I don't understand why the GS5 doesn't give the correct value.

    Can someone help me understand this issue ?

    I thank you in advance.

    Regards,

    Allan

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Leonardo
      wrote on 13 Mar 2016, 02:55 last edited by
      #2

      Hi. I get the ratio on the C++ side. Maybe it could give you some better results. Here's how I do it:

      #ifndef Q_OS_ANDROID
      	double myRatio = 1.75;
      #else
      	double myRatio = app.screens().at(0)->physicalDotsPerInch()/90;
      #endif
      ...
      QQmlApplicationEngine engine;
      QQmlContext* context = engine.rootContext();
      context->setContextProperty("myratio", QVariant(myRatio));
      ...
      

      On iOS there's not need for scaling. The system does that for you. I'm using 1.75 and 90 because my numbers were all messed up, so it was easier to fix the scaling factor than fixing all widths and heights. You should use whichever number suits you. In case you haven't seen yet, more info here:

      http://doc.qt.io/qt-5/scalability.html

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vikramg
        wrote on 22 Mar 2016, 21:22 last edited by
        #3

        I have been looking into this myself, with no conclusive information on how to reliably accomplish this. It feels like Qt 5.6 ought to automagically do the scaling for you; I intend to post a new question in this forum asking about this. In the meanwhile, the first part of this video will be of interest to you:

        https://youtu.be/nNyhsdX6BsI?t=6m24s

        There is code at 06:24 that extracts the dpi value from the Android framework. Maybe that will work better, I have not tried it myself.

        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