PDA

View Full Version : Create a label have a size = size in pixel of specified text



vql
24th October 2006, 13:40
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.

jpn
24th October 2006, 16:40
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. :)