Results 1 to 7 of 7

Thread: Garbled fonts in QGraphicsView

  1. #1
    Join Date
    Jun 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Garbled fonts in QGraphicsView

    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:
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 21 Times in 21 Posts

    Default Re: Garbled fonts in QGraphicsView

    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.

  3. #3
    Join Date
    Jun 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Garbled fonts in QGraphicsView

    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.
    Last edited by StevenB; 26th June 2007 at 22:23.

  4. #4
    Join Date
    Jun 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Garbled fonts in QGraphicsView

    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?

  5. #5
    Join Date
    Jun 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Garbled fonts in QGraphicsView

    This still happens with Qt 4.3 on Ubuntu (both 6.06 and 7.04).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Garbled fonts in QGraphicsView

    I'd say this is a problem with the font. Maybe it's a bitmap font?

  7. #7
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 38 Times in 30 Posts

    Default Re: Garbled fonts in QGraphicsView

    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).
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.