How to create a bold, red text label in Qt?

£可爱£侵袭症+ 提交于 2019-11-30 05:40:27

Try using HTML formatting: <b><font... etc </b>.

Qt Designer does it like this: <span style=" font-size:8pt; font-weight:600; color:#aa0000;">TextLabel</span>

You can use Qt StyleSheets and set the styleSheet property of QLabel

warning->setStyleSheet("font-weight: bold; color: red");

Qt supports most CSS styles on its QWidget-derived classes. You don't need to set the text format to Qt::RichText for this to work.

gnud

Qt uses a simple HTML subset for formatting.

Ramya B

You can also do it programmatically using the settext function. Something like this:

QString labelText = "<P><b><i><FONT COLOR='#ff0000' FONT SIZE = 4>";
labelText .append(Text what u want to display);
labelText .append("</i></b></P></br>");
QLabel label->setText(labelText);

You can do it in a single line as well.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!