[Interest] Display nicely truncated text in a QLabel

Lucas.Betschart at crypto.ch Lucas.Betschart at crypto.ch
Fri Jul 12 11:06:22 CEST 2013


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.

Regards


More information about the Interest mailing list