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

前端 未结 4 2069
甜味超标
甜味超标 2020-12-29 02:01

I want to write a single, bold red line in my application using Qt.

As far as I understand, I would create a QLabel, set its textFormat to rich text and give it a ri

相关标签:
4条回答
  • 2020-12-29 02:15

    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.

    0 讨论(0)
  • 2020-12-29 02:28

    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("</font></i></b></P></br>");
    QLabel label->setText(labelText);
    

    You can do it in a single line as well.

    0 讨论(0)
  • 2020-12-29 02:31

    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>

    0 讨论(0)
  • 2020-12-29 02:38

    Qt uses a simple HTML subset for formatting.

    0 讨论(0)
提交回复
热议问题