QLabel auto multiple lines

QtQlabel

Qt Problem Overview


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?

Qt Solutions


Solution 1 - Qt

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);

Solution 2 - Qt

In order to show multiple lines in QLabel, right click on QLabel and select 'change rich text'. This brings up dialog where you can type the text as you want to see including enter key. Setting the word wrap is not required for this.

If you set the word wrap as well (in QLabel properties) than it will wrap each individual line in the Qlabel if it was longer than the real estate.

enter image description here

Solution 3 - Qt

As another option to wrap text using Qt Designer, you can check the box under Property Editor for a QLabel:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRuslan F.View Question on Stackoverflow
Solution 1 - Qts4eedView Answer on Stackoverflow
Solution 2 - QtzarView Answer on Stackoverflow
Solution 3 - QtMomenView Answer on Stackoverflow