QLabel auto multiple lines

痞子三分冷 提交于 2019-11-27 17:05:56

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/12281396/qlabel-auto-multiple-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!