Qt的 - QPushButton文本格式 [英] Qt - QPushButton text formatting

查看:1442
本文介绍了Qt的 - QPushButton文本格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个QPushButton和我有文字和和图示。我要让按钮上的文字要大胆和红色。看着其他论坛,一派,失去了我的希望。看来是没有办法做到这一点如果按钮图标(当然,如果你不创造一个新的图标至极的文字+前图标)。这是唯一的方法是什么?任何人有一个更好的主意?

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. Seems there is no way to do that if the button has an icon (of course if you don't creat a new icon wich is text+former icon). Is that the only way? Anyone has a better idea?

推荐答案

您真的不需要子类更改按钮的格式,而使用样式表例如。

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;
}

应用这要改变将会使按钮文本18pt,大胆的红色按钮。您可以通过使用小窗口> setStyleSheet()

应用这一个部件层次结构中的上面将所有样式的按钮下方的 QT样式表机制非常灵活,非常有据可查的。

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

这篇关于Qt的 - QPushButton文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆