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

查看:219
本文介绍了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 ,大胆和红色。您可以通过 widget-> setStyleSheet()

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()

将此应用于上述层次结构中的窗口小部件下面的所有按钮, 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天全站免登陆