Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 更改QT Creator中按钮的颜色_C++_Qt_Button_Stylesheet_Qt Creator - Fatal编程技术网

C++ 更改QT Creator中按钮的颜色

C++ 更改QT Creator中按钮的颜色,c++,qt,button,stylesheet,qt-creator,C++,Qt,Button,Stylesheet,Qt Creator,如何更改按钮的颜色? 我已经找到了写作的方法 button->setStyleSheet("* { background-color: rgb(255,125,100) }"); 在Ui_窗口中 但每次我做的时候,Ui_Window.h都会被重新制作,我的颜色也会丢失 有人知道如何永久保留按钮的颜色吗?我正在与QT Creator合作。如果有人能指点我 非常感谢 如果您只在一个类中使用表单,则可以在其中调用ui->setupUi()后在其中添加表达式。 或者甚至直接将样式表添加到表单中,

如何更改按钮的颜色? 我已经找到了写作的方法

button->setStyleSheet("* { background-color: rgb(255,125,100) }");
在Ui_窗口中

但每次我做的时候,Ui_Window.h都会被重新制作,我的颜色也会丢失

有人知道如何永久保留按钮的颜色吗?我正在与QT Creator合作。如果有人能指点我


非常感谢

如果您只在一个类中使用表单,则可以在其中调用
ui->setupUi()
后在其中添加表达式。
或者甚至直接将样式表添加到表单中,在Qt设计器的properties视图中查找属性“stylesheet”

Aero,请考虑您不能修改Ui\u Window.h文件,因为它是由Qt Designer生成的。因此,每次重新编译.ui文件时,该头文件都将被覆盖。如我所见,您正在使用Qt Designer向布局中添加按钮。在这种情况下,您可以右键单击Qt Designer中的小部件(或在主对话框中),然后单击“更改布局…”。在那里,您可以执行以下操作:

QPushButton {
    background-color: rgb(255,125,100);
}
对于所有按钮或特定按钮:

#nameOfTheButton {
    background-color: rgb(255,125,100);
}
告诉我这是否适合你。干杯,

  • 最简单的方法是在按钮上使用样式表:

    backgroundColourButton->setStyleSheet("background-color: red");
    

看看我对这个问题的回答:Jeromes链接是正确的解决方案。您不应该触摸ui_window.h文件,因为它是在使用Qt设计器时自动生成的。它将被覆盖,因此您添加的任何更改都将消失。可能的重复感谢您的回答:D