Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [~Solved]How to ignore the system's DPI setting?

[~Solved]How to ignore the system's DPI setting?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.3k Views 1 Watching
  • 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
    Asperamanca
    wrote on last edited by
    #1

    I had a puzzling effect in a GraphicsScene, where I use QGraphicsTextItem. There are two items which show the same data. One of them shows a bigger font that the other.

    !http://members.aon.at/legends/temp/textelements.png(Two texts)!
    (The plain texts are different in the screenshot to make the items more easily distinguishable, but the effect occurs even if the text is identical)

    The solution lies in the system's DPI setting. When creating the QFont for a newly inserted item, Qt seems to recognize the system's DPI setting ("large fonts") and creates a font that looks slightly bigger.
    The second item is instead created from data read from an XML stream. The data itself is identical, but the QFont seems to be created in a context where the system's DPI setting cannot be recognized. Hence it's displayed smaller.

    The problem is that for this graphical representation, I absolutely cannot have the system's DPI setting fool around with my object sizes. They must look the same in relation to each other (e.g. a text in relation to a nearby graphic), regardless of the local system settings.

    How do I tell Qt to ignore the system's DPI setting?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      frdotnet
      wrote on last edited by
      #2

      Hello,

      I was wondering if you found any solution as to ignoring DPI settings. Thanks again, I have similar issue.

      Thanks

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        Right, I completely forgot about that thread.

        My solution is to set the font size in pixels (setPixelSize). I calculate the desired pixel size according to a "point size at 96 dpi", which is easy:

        @int pointSizeToPixelSize(const int pointSize)
        {
        return ((pointSize * 4) / 3);
        }@

        "4 / 3" is a simplification of "96 / 72", so for any other dpi, just calculate "dpi / 72"

        1 Reply Last reply
        0
        • F Offline
          F Offline
          frdotnet
          wrote on last edited by
          #4

          Thank you, it worked.

          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