PDA

View Full Version : How to display cutoff label with continuing dots?



iwatsu
20th October 2011, 21:12
I have a label that can't be bigger than fixed size. Therefore some strings are cutoff and some aren't. Is there a way to test if the text exceeds the size of the label? And then to draw "..." at the end of the string?



QHBoxLayout *l = new QHBoxLayout;
QString numberStr = "1.234556776544";
QLabel *label = new QLabel(numberStr);
label->setToolTip(numberStr);
label->setTextInteractionFlags(Qt::TextSelectableByMouse) ;
label->setFixedWidth(66);
l->addWidget(label);

Thanks!

stampede
21st October 2011, 01:03
Try to use the QFontMetrics (http://doc.qt.nokia.com/latest/qfontmetrics.html) class.