QLabel(一) 内容换行

QLabel 内容换行

  • UI界面实现
  • 代码实现

UI界面实现

在ui界面添加一个label控件。输入一长段文字,当文本超出一行时,发现没有换行。
QLabel(一) 内容换行_第1张图片
在需要换行的位置输入\n即可实现换行。
QLabel(一) 内容换行_第2张图片

代码实现

当然,以上是直接在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);

你可能感兴趣的:(QT学习,c++,QLabel)