Important: Please read the Qt Code of Conduct -

What is the correct way to use Text component to support multiple DPIs?

  • I’m trying to implement a simple mobile app in QML and currently I’m stuck with specifying proper font sizes (and other properties) of Text components so that they look similar on devices with different DPI.
    What is correct way to use Text components in QML application to support different DPIs with single code?

  • Qt Champions 2017

    We also had similar problem statement. We took the approach of reading the Screen Size, DPI. Based on these we calculated the different font size etc for different devices.

  • @dheerendra thank you for your response :) I also tried calculating font size manually but the result was insufficient.
    I would greatly appreciate if you could provide some more details on your approach:

    • how did you obtain screen size and DPI (it is possible that I used wrong values)?
    • how did you calculate font size based on screen size and DPI (I calculated ratio between reference DPI and device DPI and multiplied it by reference font size)?
    • did you use pixelSize of pointSize for you texts?
    • did you take into account different DPIs over X and Y axises? If yes, how?

  • Moderators

    you can take a look at the Scalability section of the documentation

    The calculating scaling ratio section has an example that used to help me a lot when I first was confronted with this issue.