PDA

View Full Version : Garbled fonts in QGraphicsView



StevenB
26th June 2007, 16:59
I'm attempting to use QGraphicsView and QGraphicsSimpleTextItem to display text on a page which the user can zoom in and out of. However, when I use a font size less than 6, some fonts end up garbled below a certain zoom level. I'm also using a custom QGraphicsItem, with the same result.

You can see a screenshot here: http://img457.imageshack.us/img457/2640/fontmessiz6.th.png (http://img457.imageshack.us/my.php?image=fontmessiz6.png)
The source code is here: http://botsnlinux.googlepages.com/QT_Fonts.zip
A Linux executable is here: http://botsnlinux.googlepages.com/QT_Fonts

I'm using Qt 4.2.3 on Ubuntu 7.04. The problem does not seem to appear on Windows or Mac.
Any ideas on what the problem is, and how I might fix it?

guilugi
26th June 2007, 18:24
Do the bug occur on some fonts, or all of them ?

I'll try to compile your example and check it out.
If it works on Win & Mac though, I think this is an X problem, Qt is not in cause.

StevenB
26th June 2007, 18:44
It only happens with some fonts.
It also occurs when rendering an image with QGraphicsScene::render(*QPixmap)
I've updated the code mentioned above to have a "save image" button, which renders to a pixmap and saves it as a .png image.

StevenB
27th June 2007, 20:05
From some more experimenting, it also seems that some fonts and sizes look ok, except the spacing is off.
From the QFont documentation:

Loading fonts can be expensive, especially on X11. QFont contains extensive optimizations to make the copying of QFont objects fast, and to cache the results of the slow window system functions it depends upon. This is likely the cause of the problem. Is there a way to disable or refresh this cache?

StevenB
29th September 2007, 20:42
This still happens with Qt 4.3 on Ubuntu (both 6.06 and 7.04).

wysota
29th September 2007, 20:44
I'd say this is a problem with the font. Maybe it's a bitmap font?

Bitto
30th September 2007, 07:56
Some fonts don't look good when rendered with a small point size; it's more or less out of Qt's control. However, if you instead use a standard font size, and scale the text item instead, the text usually looks fine. Try textItem->scale(0.2, 0.2) and so on and see the effect.

Oh, and btw, use point sizes for fonts in QGV can give you unexpected results, as the logical text size will vary with the DPI of your desktop - if you use pixel sizes instead, that'll translate to the item's logical units, and you'll have no surprises (like huge fonts when rendering to a high-resolution output device).