Important: Please read the Qt Code of Conduct -

Screen scaling on Android

  • So recently I decided to check out Qt Quick for Android and I've been having a problem getting things to scale correctly for different screen sizes.

    From what I've seen in the documentation, the way Qt Quick usually handles different screen resolutions/dpi levels is that the root element is scaled to full screen and then everything else will be scaled accordingly since all measurements are made relative to the root rectangle. However, whenever I run any of the example programs on my phone or in an Android emulator the program will seem to ignore the size specified in the root widget and will do all other measurements for size and position of widgets relative to the actual dimensions of the screen, which makes text practically unreadable on phones with high dpi displays.

    Here's a screenshot of the tweetsearch app running on my computer and then on my phone (Motorola Moto G, 720x1280 4.5" display).

    Ideally I'l like the proportions of all the widgets on the Android version would be the same as the Windows version, even though they're running at different resolutions.

  • You can make dpi related calculations by dividing all sizes by Screen.pixelDensity. This way controls will keep a constant physical size across multiple screen sizes.

  • Thanks for that suggestion. I tried out multiplying everything by Screen.pixelDensity, which does work to an extent, but it still doesn't feel like the best solution since I have to add " * Screen.pixelDensity" after every single measurement, which is particularly awkward since it means I have to manually update everything after I make any changes in the designer. Also, since Screen.pixelDensity returns the number of pixels per millimeter it's slightly more complicated to use than say, the system CSS uses where certain devices just have a dpi scale muliplier.

Log in to reply