PDA

View Full Version : Squeeze text in QLabel



jiveaxe
6th September 2007, 10:00
Hi,
I have a dialog with a fixed width and a QLabel in it which will display text from a database; but the lines of text that will be displayed are some smaller and some larger of the gui. I don't want enable multiline in qlabel. Is it possible squeezing ( = scale horizontally) the text and fit so the gui width? I have attached an example of what i mean (i made it with qpainter and scale() ): the first row is exceeding the dialog width while the second one is the same line (with same font size) but squeezed.

Thanks

marcel
6th September 2007, 10:04
Apart from playing with font styles and stretch factors( see QFont::setStretch) you could do it like you proposed: subclass QLabel and paint the text manually, using scale, etc.

Regards

kernel_panic
6th September 2007, 10:06
if you want to scale it or reset the pointsize of the font, you could calc with the length of the string (the string you want to draw onto the label) and the current pointsize of the font, wether its longer than the widgets width. if this is so, you reduce the pointsize of the font, by the factor you can calc with widget.width/(font.pointSize*string.length).

hope you understand, bad english

jiveaxe
6th September 2007, 10:28
Thank marcel, but the problem is that text in database contains, some time, html tags and if i want render it using this method i have to use QTextDocument and, if possible, I would avoid it. Instead if was possible stretching the content of a qlabel it was perfect.

Cheers

kernel_panic
6th September 2007, 10:35
hä?
when i understand you in the right way, you want to stretch the contents completely and not only some stringsa?
than draw on a pixmap and set the pixmap to the label!

jiveaxe
6th September 2007, 10:45
ok kernel_panic, I give it a try.

Regards