QLabel(一) 内容换行

QLabel 内容换行

UI界面实现

在ui界面添加一个label控件。输入一长段文字,当文本超出一行时,发现没有换行。
在这里插入图片描述
在需要换行的位置输入\n即可实现换行。
在这里插入图片描述

代码实现

当然,以上是直接在ui界面写文本,如果我们是在代码内部写文本,

void setWordWrap(bool on)
wordWrap : bool
This property holds the label’s word-wrapping policy.
If this property is true then label text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all.
By default, word wrap is disabled.
setWordWrap(bool)函数 ,可以实现自动识别换行,这里默认的是false。
所以在代码内实现是,只需要调用这个函数 形参给true即可。
ui->label->setWordWrap(true);

猜你喜欢

转载自blog.csdn.net/qq_45646951/article/details/110631407
今日推荐