我可以使用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.
更多推荐
发布评论