Qt - QPushButton text formatting

后端 未结 4 571
余生分开走
余生分开走 2021-01-04 23:26

I have a QPushButton and on that I have a text and and icon. I want to make the text on the button to be bold and red. Looked at other forums, googled and lost my hope. Seem

4条回答
  •  臣服心动
    2021-01-04 23:59

    You really don't need to subclass to change the formatting of your button, rather use stylesheets e.g.

    QPushButton {
        font-size: 18pt;
        font-weight: bold;
        color: #ff0000;
    }
    

    Applying this to the button that you want to change will make the buttons text 18pt, bold and red. You can apply via widget->setStyleSheet()

    Applying this to a widget in the hierarchy above will style all the buttons underneath, the QT stylesheet mechanism is very flexible and fairly well documented.

    You can set stylesheets in the designer too, this will style the widget that you are editing immediately

提交回复
热议问题