Pages

July 18, 2011

Fixing ugly Qt fonts in Openbox, Fluxbox, etc.

On Debian Squeeze at least, unless you are using GNOME or Xfce (or ostensibly KDE) or are running the configuration daemons that come with these, fonts rendered by Qt apps look like utter crap.

It seems that Qt honors neither ~/.fonts.conf, nor what's in ~/.fonts.conf.d, nor what's in /etc/fonts/conf.d. This is a problem if you want to run light-and-lean and not use the GNOME or Xfce daemons in Openbox, Fluxbox, and likely many other window managers.

After much hair pulling, I finally managed to work around the problem by using Xresources. Adding the code below to either ~/.Xresources (for user-only changes) or to a new file /etc/X11/Xresources/fonts-default (for system-wide changes) fixed the issue for me. It also fixes problems with ugly font rendering in OpenOffice.org and LibreOffice.

What I added is:
Xft.dpi: 96
Xft.antialias: true
Xft.hinting: true
Xft.rgba: rgb
Xft.autohint: false
Xft.hintstyle: hintslight
Xft.lcdfilter: lcddefault

The dpi entry is there just for good measure. Change settings as needed according to taste.

3 comments:

Anonymous said...

Thank you for posting this. I had installed crunchbang stetler to test, but Thunar's font rendering was different from apps like Firefox. I put the Xft settings into .Xdefaults but it made no difference. I didn't think to put them into Xresources. Doh. Problem solved.

I use Segoe UI for my DE UI, so I am very familiar with how it looks depending on various settings. For whatever reason, what was happening is that Thunar was rendering the font with hinting on FULL even though my ~/.fonts.conf and /etc/fonts/conf.d (which is redundant) were both configured correctly and with the same settings I use on many other distros (hintslight). Unlike many other truetype fonts, Segoe UI looks HORRIBLE when using Medium or Full hintstyle (actually, either setting w/ autohint off will force the use of the ByteCode Interpreter instead of the autohinter, which makes Segoe UI look terrible. FYI, the autohinter is used regardless of the autohint setting when hintslight is used. Dumb - but true. I view this as a bug of the fontconfig system).

NGA said...

Wow, copying and pasting your lines has seen such a huge improvement in my qt fonts. Thank you!
Perhaps qt5 will fix this?
I'm using infinitaly patches + siduction.

NGA said...

Wow, copying and pasting your lines has seen such a huge improvement in my qt fonts. Thank you!
Perhaps qt5 will fix this?
I'm using infinitaly patches + siduction.