PDA

View Full Version : QLabel - visible text function or something else



john
18th April 2008, 09:37
hello,

I'm making something like music player and I'm using QLabel to display the track title.
Sometimes the track title is long and the result is:
http://img155.imageshack.us/img155/4849/qlabelxq8.png

I must create algorithm to show it all in parts. I want to ask: is there a function that return me only the visible text?

thanks all

aamer4yu
18th April 2008, 17:32
Not sure of any such function.
I guess u want to show the whole text.
Would suggest 2 solutions -
1) Use setToolTip() to display the whole text
2) Inherit QLabel and make the text scrolling. Its easy. Set a fixed no of chars to display. Now display the string - fullString.mid(ith_position,no_of_chars_to_displaY ) using a QTimer .

Hope this helps :)

john
20th April 2008, 11:00
Yes, the scrolling is good method, but I don't know how many chars to display, because my form is resizable. May be I need to create funkction that calculate the chars from the label width.

Thank you...

wysota
20th April 2008, 12:26
There is such a function. Take a look at QFontMetrics::elidedText().