Results 1 to 2 of 2

Thread: QFontMetrics boundingRect vs horizontalAdvance with monospaced fonts

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFontMetrics boundingRect vs horizontalAdvance with monospaced fonts

    QFontMetrics::boundingRect() is returning a rectangle width from the leftmost black pixel to the rightmost black pixel (Assuming a black pen).

    The horizontalAdvance includes the whitespace that precedes/follows the end characters when rendered.
    If you use QPainter::boundingRect() you will get a rectangle that contains the string neatly

    The averageCharWidth() is that of all the glyphs in the font (not just the ones in your string), looks to be the rendered pixels only, and may be subject to rounding.

  2. The following user says thank you to ChrisW67 for this useful post:

    tuli (9th May 2021)

Similar Threads

  1. Replies: 3
    Last Post: 9th June 2022, 16:29
  2. Replies: 1
    Last Post: 22nd April 2014, 15:58
  3. Adding Arabic fonts and CJK (China Japan Korean) fonts
    By kishore7771 in forum Qt Programming
    Replies: 0
    Last Post: 30th July 2013, 18:33
  4. A crash in QFontMetrics::boundingRect()
    By npirocanac in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th February 2013, 11:47
  5. How to specify QRect argument to QFontMetrics::boundingRect()
    By John Mcgehee in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2010, 04:50

Tags for this Thread

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.