如何正确设置QPushButton的颜色? [英] How to correctly set the color of a QPushButton?

查看:2480
本文介绍了如何正确设置QPushButton的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用成功改变QPushButton的颜色 setStyleSheet ,但因为我使用Qt Creator中,使图形用户界面,我每次运行qmake的时间,使中,调用来setStyleSheet消失。

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.

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

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的的或没有。

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

从你discribing什么,好像你正在写自己的一些code到 ui_window.h ,这是错误的方式来设置样式表。

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

您可以将它设置在窗口类的构造函数,或者从GUI编辑器设置( Qt设计的):

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


  • 双集团公司在 window.ui 在所显示的项目树的 Qt Creator的

  • 选择您的 QPushButton 在GUI编辑器。

  • 找到在属性编辑器中的的styleSheet 属性。

  • 在三个点CLIC( ... ):这会带来一个样式表编辑器

  • double-clic 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.
  • clic 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.

这篇关于如何正确设置QPushButton的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆