Results 1 to 2 of 2

Thread: Create a label have a size = size in pixel of specified text

  1. #1
    Join Date
    Jun 2006
    Location
    Vietnam
    Posts
    59
    Thanks
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Create a label have a size = size in pixel of specified text

    I want create a label have a empty text. If i preview it, its size is small (if the form contains it in layout). In the case, i want to create a label have a size = size in pixel of specified text. Example: by operation, i fill the text "1234" into this label. Then the label will zoom -> the form will also zoom. This is not good. So I want to create this label have a size = size of "1234".

    Thanks.

  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: Create a label have a size = size in pixel of specified text

    You can use QFontMetrics to calculate the size of a string for a given font. Is the text static or is it going to change? Maybe you could do a trick like setting the text color to the same as the labels background. This way QLabel would handle the sizing properly.
    J-P Nurmi

Similar Threads

  1. Replies: 15
    Last Post: 31st January 2020, 19:25
  2. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49

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.