PDA

View Full Version : How to fix the size of a QLabel with variable text



Coises
1st February 2010, 01:51
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?

wysota
1st February 2010, 02:01
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.