如何正确设置QPushButton的颜色?(How to correctly set the color of a QPushButton?)

编程入门 行业动态 更新时间:2024-10-28 22:23:26
如何正确设置QPushButton的颜色?(How to correctly set the color of a QPushButton?)

我可以使用setStyleSheet成功更改QPushButton的颜色,但是因为我使用QT Creator来制作GUI,所以每次运行qmake和make时,对setStyleSheet的调用消失。

更改按钮的调色板也不会更改其颜色。

什么是最好的方式来改变按钮的颜色,而不必每次我手动更改我的ui_window.h文件我qmake?

I can successfully change the color of a QPushButton using setStyleSheet, but because I'm using QT Creator to make the GUI, every time I run qmake and make, the calls to setStyleSheet disappear.

Changing the palette of the button doesn't change its color either.

What's the best way to change to color of the button without having to manually change my ui_window.h file every time I qmake?

最满意答案

无论您是否使用Qt Creator ,使用样式表都是正确的方式。

从你所描述的内容看来,你似乎正在编写一些代码到ui_window.h ,这是设置样式表的错误方法。

你可以在你的window类的构造函数中设置它,或者从GUI编辑器( Qt Designer )中设置它:

Qt Creator显示的项目树中双击window.ui 。 在GUI编辑器中选择你的QPushButton 。 在属性编辑器中找到styleSheet属性。 点击三个点( ... ):这将带来一个样式表编辑器。

如果您使用样式表编辑器设置样式表,则每次重建应用程序时都不会消失。

Using style sheets is the right way to do, no matter you're using Qt Creator or not.

From what you are describing, it seems you are writing yourself some code into the ui_window.h, which is the wrong way to set the stylesheet.

You can set it in the constructor of your window class, or set it from the GUI editor (Qt Designer) :

double-click on your window.ui in the project tree displayed by Qt Creator. select your QPushButton in the GUI editor. locate the styleSheet property in the properties editor. click on the three dots (...) : this will bring a stylesheet editor.

If you set the stylesheet with the stylesheet editor, nothing will disappear each time you are rebuilding your app.

更多推荐

本文发布于:2023-08-01 14:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1360081.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何正确   颜色   QPushButton   color   correctly

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!