QLabel auto multiple lines

Ruslan F. picture Ruslan F. · Sep 5, 2012 · Viewed 50.7k times · Source

For example, we have a QLabel with MaximumWidth set to 400.
When we try to display some text with pixel width more than 400, it's shown cut off.
Is there any way to make QLabel display this string in multiple lines without using QFontMetrics or the like?

Answer

s4eed picture s4eed · Sep 5, 2012

If I understood your question correctly, you should use the setWordWrap function for your label, with true as its parameter.

QLabel lbl("long long string");
lbl.setWordWrap(true);