Results 1 to 4 of 4

Thread: Only integers from QFontMetricsF width

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

    Default Only integers from QFontMetricsF width

    I'm getting only integer values from QFontMetricsF::width() and QFontMetricsF.boundingRect().width().
    I'm trying to use the width to draw a box with GraphicsView, but because of the integer coordinates, the box sometimes overlaps the text.

    Here's the code I'm using:
    Qt Code:
    1. QFont font("Sans", 12);
    2. font.setPointSizeF(13.2524);
    3. fontsizer = new QFontMetricsF(font);
    4. std::cout << "width: " << fontsizer->width("string") << std::endl;
    To copy to clipboard, switch view to plain text mode 
    Am I doing something wrong?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Only integers from QFontMetricsF width

    Any particular reason why not to use readily available QGraphicsTextItem or QGraphicsSimpleTextItem?
    J-P Nurmi

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

    Default Re: Only integers from QFontMetricsF width

    Any particular reason why not to use readily available QGraphicsTextItem or QGraphicsSimpleTextItem?
    I probably could use QGraphicsTextItem. However, I already have significant amount of code which uses QPainter::drawText inside a custom class derived from QGraphicsItem. I'd like to fix an integer-size related bug in this class without re-writing a lot of code.

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

    Default Re: Only integers from QFontMetricsF width

    Sorry for reviving an old thread, but I'm still having problems with this. I'm doing a bunch of custom painting, and need to be able to line up my text. I'm running Qt 4.4 on Ubuntu Hardy.

Similar Threads

  1. How to obtain the width of a QTableWidget?
    By Giel Peters in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 22:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.