[Qt-interest] Default application Font

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jan 29 16:17:48 CET 2009


Jon Flowers wrote on Thursday, January 29, 2009 3:01 PM:

> ...
> Also looking at the preferences on that machine its default font is
> sans 10 and I am getting Helvetica 13 in my app. But I have
> overridden the font to sans serif and that seems to hold, but not the
> size.

Hmm, again I have to ask, which "preferences" are you referring to? Are you running Gnome or KDE? If the later, then chances are pretty good that Qt picks up the proper fonts (as set by KDE), if you do not explicitly set them in your application. That is, chances are pretty good that a call to:

  http://doc.trolltech.com/4.4/qapplication.html#font

would return the same font (and size, off course) which you have set in the "KDE font control panel". If on the other hand you are referring to some "Gnome Preferences" then I don't know whether Qt will correctly pick them up (especially if you have KDE and Gnome installed in parallel).

 In a related thread ("Russian fonts") the tool qtconfig-qt4 was mentioned (which I think is Unix specific). It should probably tell you what Qt takes as the "default font".

Alternatively you can try explicitly setting the desired font in your app (instead of relying on some shaky system preferences):

int main(...)
{
  // choose a "font family" which is really available on your system!
  QApplication::setFont(QFont("Arial", 10));
  QApplication app(...);

  ...
  Font font = QApplication::font();
  // 'font' should now refer to a "Arial, 10" font
}


That reminds me: I once had the problem that some older Linux distro did not correctly detect my "Apple Cinema 21" display, and hence the screen DPI settings were completely bogus (a "generic display" was assumed). This resulted in the fonts being rendered too large in XEmacs ("pure XLib based", I assume). AFAICR also Firefox was affected - notably a GTK application ;)

Because obviously the underlying GTK/XLib/FreeType font framework/renderer thought it would be nice to scale the fonts depending on the DPI, so they appear at the same size on every screen (17", 20", 21", 24", ...). Once I had set the proper DPI the font appeared at "normal" size.

So your previous statement "I have moved from the glade/gtk+ environment and when a font gets set it is that way no matter the machine it gets run on" has already been proven wrong by that ;) (because depending on the user settings it can still appear at different sizes, even when you request an "Arial, 10"). Ironically Qt applications were not affected by the DPI settings...


Hope that helps,
  Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22




More information about the Qt-interest-old mailing list