QLabel 自动多行 [英] QLabel auto multiple lines

查看:34
本文介绍了QLabel 自动多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我们有一个 QLabel,MaximumWidth 设置为 400.
当我们尝试显示一些像素宽度超过 400 的文本时,它显示被截断.
有没有办法让 QLabel 在不使用 QFontMetrics 等的情况下多行显示这个字符串?

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?

推荐答案

如果我正确理解你的问题,你应该使用 setWordWrap 函数用于您的标签,true 作为其参数.

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

这篇关于QLabel 自动多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆