title: Convert pixel size to point size for fonts on multiple platforms
body: <p>I need a way to translate point size and pixel size between multiple platforms.</p>
  
  <p>I have a Qt application that must run on multi-platform, including an embedded Linux on a type of tablet.<br>
  It is expected that users can save files created by the application, on a desktop (either windows or linux) and open on the custom device.</p>
  
  <p>The data consists of drawings, and text - <code>QGraphicsItem</code>s on a <code>QGraphicsScene</code>. Some text items are "rich text", so we can change font on fragments of text.</p>
  
  <p>For normal text, including all UI text, we used pixel size instead of point size to achieve a similar look. But rich text defies me: the <code>QTextCharFormat</code> doesn't have a <code>pixelSize()</code> option. Only <code>setFontPointSize()</code> and <code>fontPointSize()</code>.  I can use <code>font().setPixelSize()</code> then <code>setFont()</code> but the result is that when saving, using the <code>html()</code> method, I lose all font information. (Must be a qt bug ?)</p>
  
  <p>So, what I need is to be able to use pixel size everywhere, and then calculate the point size to set it on paragraphs (and go in reverse when reading sizes).</p>
  
  <p>But - what is the relation between pixel size and point size ? If I determine both, for a given font, on the current platform, can I establish some sort of equation to use ?</p>
  
  <p>Edit - I found an interesting post - it seems to do what I want, but it is specific to only OSX. <a href="https://stackoverflow.com/a/25929628/1217150">https://stackoverflow.com/a/25929628/1217150</a><br>
  My target platforms, Windows / Linux / OSX but also, especially, a custom tablet running embedded Linux, and possibly in the future Android devices. </p>
  
  <p>Qt 4.8</p>
  
  <p>Edit - using the conversion in answer below, left text using setPixelSize(20) and right text using setPointSize(20 * screenDpi) where </p>
  
  <pre><code>qreal screenDpi = QApplication::desktop()-&gt;physicalDpiX() / 72.;
  </code></pre>
  
  <p>Note the size is not the same... (running in windows, have not yet tested on other platforms)</p>
  
  <p>I even tried</p>
  
  <pre><code>#ifdef Q_OS_WIN32
      qreal screenDpi = QApplication::desktop()-&gt;physicalDpiX() / 96.;
  #else
      qreal screenDpi = QApplication::desktop()-&gt;physicalDpiX() / 72.;
  #endif
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eDmeu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eDmeu.png" alt="enter image description here"></a></p>