Results 1 to 2 of 2

Thread: Fit text to space

  1. #1
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Fit text to space

    Given a QString, a QFont and a QRect (or a QLabel), what is the simplest way to find the largest QFont::setPixelSize that can be set so that the QString, whien rendered in the QFont, will fit within the space (QRect or already sized QLabel)?

    If there is no direct way to do it... what is the Qt equivalent of Windows’ GetTextExtentPoint32?

  2. #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: Fit text to space

    I'm not aware of any one call that gives the answer you seek for font size.

    You should look at QPainter::boundingRect(), QFontMetrics::boundingRect(), QFontMetrics::size(), and friends for inspiration.

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

    Coises (1st February 2010)

Similar Threads

  1. QTableView empty space or too little space.
    By davemar in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2009, 16:00
  2. Replies: 1
    Last Post: 26th July 2009, 15:08
  3. Replies: 1
    Last Post: 3rd September 2008, 14:16
  4. Height of the text without balnk space at the top
    By THRESHE in forum Qt Programming
    Replies: 6
    Last Post: 19th March 2008, 13:33
  5. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

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.