简体   繁体   English

QT5:如何将一个样式表应用于不同的小部件?

[英]QT5: How to apply one stylesheet to different widgets?

I am fairly new to QT and I am playing around with it a bit. 我对QT相当陌生,并且正在试用它。 I did a lot of android programming in the past. 过去我做了很多android编程。 So I really love the android XML-Styling-System where you can change properties for each induviduell gui-element, you can apply styles to buttons (so they look always the same and there is just one place to change properties for all elements the style is applied to) or you can even create themes, so that you set up one set of styles for your whole application. 因此,我非常喜欢android XML-Styling-System,您可以在其中更改每个induviduell gui元素的属性,可以将样式应用于按钮(因此它们看起来总是相同的,只有一个地方可以更改样式的所有元素的属性应用于),或者甚至可以创建主题,以便为整个应用程序设置一组样式。

Is there anything similiar to this in QT? QT中有什么与此类似的东西吗? I've seen the stylesheet property to add a stylesheet to a widget. 我已经看到了将样式表添加到小部件的stylesheet属性。 But let's assume I have 20 buttons and they are all suposed to look the same (eg all have a green background). 但是,让我们假设我有20个按钮,而且它们都应该看起来相同(例如,所有背景均为绿色)。 Now I can apply a stylesheet to each button. 现在,我可以将样式表应用于每个按钮。 Now I change my mind and I want them red. 现在我改变主意了,我想让他们变红。 Do I have to go into each stylesheet again to change it? 是否需要再次进入每个样式表进行更改?

I hope my point came across. 希望我的观点能明白。 Btw, what is QML? 顺便说一句,什么是QML? Seems very powerful but I didn't get it yet. 似乎功能很强大,但我还没明白。 Is it just a different way of styling? 这只是一种不同的样式方式吗?

Thanks. 谢谢。

The selector part of the stylesheet language allows you to have rules that apply to all instances of a class, or all instance of classes of the same base classs, etc. 样式表语言的选择器部分允许您具有适用于类的所有实例或相同基类的类的所有实例的规则。

You can set stylesheets on individual widgets or globally, see QWidget::setStyleSheet() and QApplication::setStyleSheet() respectively. 您可以在单个小部件上或全局设置样式表,分别参见QWidget::setStyleSheet()QApplication::setStyleSheet()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM