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.
doc.setDefaultStyleSheet(QStringLiteral("span { background-color: %1}") .arg(textColor.name())); doc.setHtml(tr("<p>Register: <span>Qt for test Qt for test Qt for test Qt for test</span></p>")); doc.setDocumentMargin(1);
void Widget::paintEvent(QPaintEvent *event) { QPainter painter(this); QTextDocument doc; QColor textColor = "green"; //文字颜色 doc.setDefaultStyleSheet(QStringLiteral("span { background-color: %1}") .arg(textColor.name())); doc.setHtml(tr("<p>Register: <span>Qt for test Qt for test Qt for test Qt for test</span></p>")); doc.setDocumentMargin(1);
auto r = this->rect(); r.setWidth(r.width() / 2); r.setHeight(r.height() / 2); r.moveCenter(r.bottomRight()); //构建个画图用的矩形。这里是放在中间的1/4个矩形