Screen.Size questions

  • Hi everybody,
    when developing in Qt QML there is an object called Screen that is useful to size some items ( But there is something that I don't understand at all.

    I have a One Plus X, its width specs are (
    Width in physical PIXELS: 1080 pixels
    Width in mm: 69 mm (so the screen a little bit less)

    So when I run this part of code:

    console.log("Width in pixels: " + Screen.width)
    console.log("Pixel Ratio: " + Screen.devicePixelRatio )

    It returns me

    qml: Width in pixels: 360
    qml: Pixel Ratio: 3

    So I understant that Screen.width returns he width in logical pixels:

    Device Pixel Ratio: The ratio between physical pixels and device-independent pixels for the screen.

    360 logical pixels = 1080 pyhisical pixels * 1 logical pixel/3 pyhisical pixels

    And in documentation it is called that the property pixelDensity:
    Pixel Density: The number of physical pixels per millimeter.
    But if I check this:

    console.log("Pixel Density: " + Screen.pixelDensity )
    qml: Pixel Density: 5.786108689334496

    It returns a density that NOT corresponds in the density of physical pixels because

    **1080** physical pixels / **5.78** physical pixels/mm = 186.85 mm

    And the width IS NOT 186.85, instead of that:

    **360** logical pixels / **5.78** logical pixels/mm = 62,28 mm

    That it match with the with of my device.

    So... The pixel density documentation is not OK?

    It would be: (The number of physical logical pixels per millimeter) ?

    Thank you very much

  • Hi! Looking at qquickscreen.cpp, it's not a documentation bug:

    qreal QQuickScreenInfo::pixelDensity() const
        if (!m_screen)
            return 0.0;
        return m_screen->physicalDotsPerInch() / 25.4;

    So it must be something else, maybe a bug in some driver or in the platform abstraction layer for your particular device. I'd recommend to file a bug,

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.