在构造函数中定义一个标签,设置自动换行和样式表
-----mywidget.cpp-----
#include "mywidget.h" #include "ui_mywidget.h" #include <QLabel> MyWidget::MyWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MyWidget) { ui->setupUi(this); this->setWindowTitle("样式表的使用"); QLabel *lbl = new QLabel(this); lbl->setText(" 彩笔描空,笔不落色,而空亦不受染;"\ "利刀割水,刀不损锷,而水亦不留痕 。"\ "得此意以持身涉世,感与应俱适,心与境两忘矣。"); lbl->move(, ); lbl->setMaximumWidth(); lbl->setWordWrap(true); lbl->setStyleSheet("QLabel{font-family:微软雅黑; font-size:16pt; "\ "color:green; background-color:yellow}"); } MyWidget::~MyWidget() { delete ui; }