更改 QT Creator 中按钮的颜色
如何更改按钮颜色? 我找到了通过
button->setStyleSheet("* { background-color: rgb(255,125,100) }");
在 Ui_Window.h 中
编写来做到这一点的方法,但每次我 qmake 时,Ui_Window.h 都会被重新制作,并且我会失去颜色。
有谁知道如何永久保留按钮的颜色?我正在与 QT Creator 合作。如果有人可以指导我=D
非常感谢!
How do I change a buttons color?
I have found ways to do it by writing
button->setStyleSheet("* { background-color: rgb(255,125,100) }");
in Ui_Window.h
But everytime I qmake, the Ui_Window.h gets remade and I lose my colors.
Does anyone know how to permanently keep the colors of the button? I am working with QT Creator. If someone could direct me =D
Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是在按钮上使用样式表:
Easiest way would be to use a style sheet on the button:
Aero,请注意您不得修改 Ui_Window.h 文件,因为它是由 Qt Designer 生成的。因此,每次重新编译 .ui 文件时,该头文件都会被覆盖。正如我所看到的,您正在使用 Qt Designer 将按钮添加到布局中。在这种情况下,您可以右键单击 Qt Designer 中的小部件(或在主对话框中),然后单击“更改布局...”。在那里,您可以执行以下操作:
对于所有按钮,或对于特定按钮:
告诉我这是否适合您。干杯,
Aero, take into account that you MUST not modify Ui_Window.h file since it is generated by Qt Designer. So, every time you recompile the .ui file, this header file will be overwriten. As I see, you are using Qt Designer to add buttons to the layout. In this case, you can right click on a widget (or in the main dialog) in Qt Designer and click then in 'Change layout...'. On there, you can do something like:
for all buttons, or for an specific button:
Tell me if this works for you. Cheers,
如果您仅在一个类中使用表单,则可以在调用其中的
ui->setupUi()
之后在其中添加表达式。或者甚至直接将样式表添加到表单中,在 Qt 设计器的属性视图中查找属性“StyleSheet”。
If you use your form only in one class, you may add your expression there, after calling to
ui->setupUi()
in it.Or even add stylesheet directly to form, look for property 'StyleSheet' in properties view of Qt designer.