title: How to locate and use fonts in Qt for Embedded Linux?
body: <p>This question might be related to this question:
  <a href="https://stackoverflow.com/questions/18276942/where-does-qt-go-to-look-for-fonts">Where does QT go to look for fonts?</a></p>
  
  <p>Im working with Ubuntu 14.04 and Qt for Embedded 4.8 and want to change the font of my application globally but I can only use a very small subset from my installed fonts.</p>
  
  <p>The style of my application is loaded from a CSS file where I write:</p>
  
  <pre><code>QWidget {
     font-family: "DejaVu Sans"; /*or any other font*/
  }
  </code></pre>
  
  <p>The problem is that Qt doesn't seem to be able to locate my installed fonts. According to the documentation <a href="http://doc.qt.io/qt-4.8/qt-embedded-deployment.html" rel="nofollow noreferrer">Deploying Qt for Embedded Linux Applications</a> Qt applications look for fonts in the <em>lib/fonts/</em> directory and specifically for the a file called <em>fontdir</em>. I don't know what this file is about and I cannot find it either. My full path for the fonts (for the debug build) is: <em>/usr/local/Trolltech/QtEmbedded-4.8.6-x86-dbg/lib/fonts</em></p>
  
  <p>I use the QFontDatabase that can be found <a href="http://doc.qt.io/qt-4.8/qfontdatabase.html#details" rel="nofollow noreferrer">in the Qt 4.8 docu</a> to print all my available fonts. Unfortunately the output is:</p>
  
  <pre><code>DejaVu Sans: Normal (11)
  fixed: Normal (7 12)
  helvetica: Normal (8 10 12 14 18 24) Italic (8 10 12 14 18 24) Bold (8 10 12 14 18 24) Bold Italic (8 10 12 14 18 24)
  japanese: Normal (23)
  micro: Normal (4)
  unifont: Normal (16)
  </code></pre>
  
  <p>But I have way more fonts installed. The <em>DejaVu Sans</em>, for example exists in <strong>bold</strong> and other types too but only the "Normal" one is found. Here is only a small subset of fonts located in my fonts folder (those are located in the Qt folder for release and debug as well):</p>
  
  <pre><code>couri.pfa
  cour.pfa
  cursor.pfa
  dejavu_sans_11_50.qpf2
  DejaVuSans-BoldOblique.ttf
  DejaVuSans-Bold.ttf
  DejaVuSansMono-BoldOblique.ttf
  DejaVuSansMono-Bold.ttf
  DejaVuSansMono-Oblique.ttf
  DejaVuSansMono.ttf
  DejaVuSans-Oblique.ttf
  DejaVuSans.ttf
  DejaVuSerif-BoldOblique.ttf
  VeraMono.ttf
  VeraSeBd.ttf
  VeraSe.ttf
  Vera.ttf
  </code></pre>
  
  <ol>
  <li><p>What is the <em>fontdir</em> file for, do I need it and how do I create it?</p></li>
  <li><p>What do I have to do so that Qt finds all my installed fonts?</p></li>
  <li><p>Is there a way to simply use a copy of my font of interest and put it into a sub-directory of my application to treat it like an icon so that I don't have to mess around with all the system locations?</p></li>
  </ol>
  
  <p><strong>Edit:</strong> According to this <a href="http://www.qtcentre.org/threads/52402-unable-to-find-font-when-placed-under-lib-font-dir" rel="nofollow noreferrer">thread</a> I think that I have also no support for TTF fonts. I had a look into my fonts and it appears that all *.qpf and *.qpf2 fonts are found. So I will try to convert my TTFs into QPFs. </p>