Results 1 to 2 of 2

Thread: How to fix the size of a QLabel with variable text

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

    Default How to fix the size of a QLabel with variable text

    I have some nested horizontal and vertical layouts. A couple elements of the layout are QLabels which contain rich (HTML) text that changes as execution of the program progresses.

    It is possible to work out at compile time an HTML value for each of these QLabels which represents the maximum width and height that will ever be required.

    I can define the layouts in Designer, but if I make the layouts contingent on the requisite size of the QLabels, things have a tendency to shift around disconcertingly as the contents of the QLabels change. On the other hand, were I to fix the size of the QLabels, things would probably go wrong when one system or another had different fonts available, or a different points-to-pixels display setting.

    What is the most straightforward way to specify, for each QLabel containing variable rich text, a sample that represents the maximum size that will be needed, then fix the size of the QLabel to those dimensions so it doesn’t resize as different text is displayed in it?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to fix the size of a QLabel with variable text

    What is sometimes used is to set the maximum text that can be set to the label during runtime, then capture this size (it will be returned by sizeHint()) and set the captured value as fixed size of the label.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Coises (1st February 2010)

Similar Threads

  1. Replies: 1
    Last Post: 2nd August 2008, 15:46
  2. adjust font size to QLabel-size
    By hunsrus in forum Qt Programming
    Replies: 0
    Last Post: 9th July 2008, 14:33
  3. Replies: 1
    Last Post: 30th November 2007, 10:03
  4. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56
  5. Replies: 1
    Last Post: 24th October 2006, 16:40

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.