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



  • 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?



  • Hello,

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

    Thanks



  • 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"



  • Thank you, it worked.


Log in to reply
 

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