[Interest] Display nicely truncated text in a QLabel

André Somers andre at familiesomers.nl
Fri Jul 12 11:15:23 CEST 2013


Op 12-7-2013 11:06, Lucas.Betschart at crypto.ch schreef:
> Hi
>
> I would derive from QLabel, get the length of it (in pixel) with frameWidth() use QFontMetrics QWidget::fontMetrics () with int QFontMetrics::width ( const QString & text, int len = -1 ) to get the length of the text in pixels, check if it fits, and if no cut some chars and replace it with … until it fits. You would have to check every time again when the user changes the windows size..
>
> Maybe someone else knows a nicer way.
>
> I don’t think they will implement such features for QWidgets anymore, since there is QML now.
If you're using QFontMetrics anyway, you might as well use it's 
elidedText method to get the text to render.

André

-- 
You like Qt?
I am looking for collegues to join me at i-Optics!




More information about the Interest mailing list