[英]How to change QPushButton icon using stylesheets in Qt app
Is it possible to set and change the icon on a QPushButton using stylesheets? 是否可以使用样式表在QPushButton上设置和更改图标?
I need this for a Windows-based white-label Qt4.5 application that customers stylize using stylesheets. 我需要这个基于Windows的白标Qt4.5应用程序,客户使用样式表进行样式化。
Thanks. 谢谢。
A little late for a reply, but in case anyone else pops on this via google; 回复有点迟,但万一有人通过谷歌突然出现这个问题;
You can add the icon by changing the QAbstractButton-property. 您可以通过更改QAbstractButton属性来添加图标。 Simply use:
只需使用:
QAbstractButton {
qproperty-icon: theme_url("/button_action/add");
}
The type-selector (QAbstractButton), enables you to set the style for the selected object and all its subclasses . 类型选择器(QAbstractButton)使您可以为所选对象及其所有子类设置样式。 Since QProcessButton extends the QAbstractButton, this will do the trick.
由于QProcessButton扩展了QAbstractButton,这将起到作用。 (Of course you could also use the
QPushButton
type-selector here). (当然你也可以在这里使用
QPushButton
类型选择器)。
For more information on how to use selectors, I found this quite helpful. 有关如何使用选择器的更多信息,我发现这非常有用。
If you want to learn more about the button-properties, refer to the QT-Documentation here . 如果您想了解有关按钮属性的更多信息,请参阅此处的QT文档。
PS. PS。 In case you want to change the icon, once the button is clicked, use
如果您想要更改图标,单击该按钮后,请使用
qproperty-icon: url(":/Icons/before_click.png") off,
url(":/Icons/after_click.png") on ;
对。
border-image: url(/url/to/image);
You can use: 您可以使用:
image: url(/url/to/image);
See http://doc.qt.io/qt-5/stylesheet-reference.html#image-prop and http://doc.qt.io/qt-5/stylesheet-customizing.html#box-model . 请参阅http://doc.qt.io/qt-5/stylesheet-reference.html#image-prop和http://doc.qt.io/qt-5/stylesheet-customizing.html#box-model 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.