1
votes

What is the best way to determine if text-size exceeds width of QLabel? And according to that, change the text-size?

I have a QLabel with word-wrap option set to true, but when text is so long it is being cropped from left and right side.

1
Is your label widget managed by a layout? If so, you should set the sizeConstraint on the topmost layout (label->widnow()->layout()), so that the window will be always sufficiently large to hold all of the contents.Kuba hasn't forgotten Monica

1 Answers

2
votes

You might want to try this approach:

QLabel label;
QRect r = label.fontMetrics().boundingRect( "My text" ) );
int textWidth = r.width();