Friday, 21 July 2017

QT Fonts on low resolution Displays

QT TTF Font rendering on low resolution industrial displays

I tried all kind of ttf fonts with all the font rendering & antialising flags. 
The rendering was looking bad, pixels bleeding in to neighborhood [Left Side]. 
Now they look just fine (right side)

To outcome the TTF rendering engine I used bitmap based fonts. *.BDF.
I am running Linux  Ubuntu 16.04.1 LTS

What I used.

  • Original ttf font file. 
  • fontforge  from:  sudo apt-get install fontforge
  • ttf2bdf from:
    • Untar ttf2bdf and copy it to ~/bin or /usr/bin as sudo


  • Convert ttf font to bdf of different sizes you want. 8 9 10 12 14
    • type in the shell
      • ttf2bdf -p 8 ./MyFont.ttf -o MyFont8.bdf 
      • ttf2bdf -p 9 ./MyFont.ttf -o MyFont9.bdf 
      • ttf2bdf -p 10 ./MyFont.ttf -o MyFont10.bdf  
      • ttf2bdf -p 12 ./MyFont.ttf -o MyFont12.bdf 
      • ttf2bdf -p 14 ./MyFont.ttf -o MyFont14.bdf 
  • Change Face Names in each font using fontforge for each font.
    • In shell run fontforge
    • open one by one MyFont#.bdf
    • MainMenu-> Element->FontInfo
      • Change (for each size pick different names)
        • FontName
        • FamilyName
        • Name For Humans
        • Copyright
    • Press OK
    • Main Menu -> GenerateFonts
      • Give it another mane MyFont#_pix.bdf
      • Press Save
        • Generated name would append Medium, don't worry, can rename it in file explorer and with move command
  • QT Code
    •  Copy your fonts into a folder eg. /home/you/bdfs 
    • In the c-tor of Your MainApp

QMyApp::QMyApp(int &argc, char **argv):QApplication(argc,argv)

      QDirIterator it("/home/you/bdfs", QDirIterator::NoIteratorFlags);
       while (it.hasNext()) {
        QString fn =;

       have a public. whatever member in QYourApp
       std::map<QString,Font> _fonts; 

    QStringList fm = QFontDatabase().families();
    for(auto a : fm)
        QString fn = a;
            QFont f = QFont(a);
_fonts[a] = f;

    // set default for all
    QApplication::setFont(_fonts["MyFont12PixMedium"]);// this is the name

// use other fonts as
void someCode()
    QMyDialog d...; 
    QMyApp* papp = dynamic_cast<QMyApp *>(QCoreApplication::instance());

Marius C. July 2017


No comments:

Post a Comment