Results 1 to 2 of 2

Thread: Autosize QLabel Font in a QFrame (in a vertical layout)

  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Autosize QLabel Font in a QFrame (in a vertical layout)

    I have a QMainWindow that has a vertical layout that's laid out in a grid.

    The vertical layout contains a QFrame. The QFrame has a QLabel. The widget hierarchy can be seen in the attached screenshot.

    Everything resizes as I'd expect when the QMainWindow size is changed. The QFrame and QLabel sizes change, but the text size in the QLabel remains fixed.

    I want to adjust the QLabel font to make the text as big as possible without the text being clipped.

    I thought I could use the label's fontMetrics and adjust the font size until the fontMetrics height was just less than the containing QFrames height. But, I've found I can adjust the font size so that the text isn't clipped, yet the FontMetrics height is BIGGER than the containing QFrame.

    So, I don't know what to use for the target fontMetrics height.

    Here's what the layout looks like (from Qt Designer):

    qtheat.png

    The QLabel text I'm trying to autosize is Race.

  2. #2
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Autosize QLabel Font in a QFrame (in a vertical layout)

    The ScaleTextlabel class posted by Vronin works well for me:



    https://forum.qt.io/topic/36088/auto...-in-qlabels/10

Similar Threads

  1. Replies: 5
    Last Post: 30th June 2016, 10:53
  2. "Autosize" QLabel according to text?
    By Raadush in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2012, 08:36
  3. Replies: 0
    Last Post: 14th February 2012, 13:07
  4. Replies: 1
    Last Post: 2nd August 2008, 16:46
  5. Vertical QLabel
    By ToddAtWSU in forum Qt Programming
    Replies: 4
    Last Post: 12th September 2006, 15:14

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.