Python PyQt QPushButton 背景色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20668060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PyQt QPushButton Background color
提问by Trying_hard
I have the follow code:
我有以下代码:
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(0, 550, 150, 31))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
How do I get the background color of this button to change. I have tried using Palette and I am having no success. I would like the color to be red. I can't seem to call it correctly. Any help would be great.
如何更改此按钮的背景颜色。我曾尝试使用 Palette,但没有成功。我希望颜色是红色。我似乎无法正确称呼它。任何帮助都会很棒。
采纳答案by Alvaro Fuentes
You can change the style of the button:
您可以更改按钮的样式:
self.pushButton.setStyleSheet("background-color: red")
It's like CSS.
这就像 CSS。
回答by AB Bolim
Here is a sample code. You can choose any style to set background color.
这是一个示例代码。您可以选择任何样式来设置背景颜色。
QPushButton button1, button2, button3;
button1.setStyleSheet("background-color: red");
button2.setStyleSheet("background-color:#ff0000;");
button3.setStyleSheet("background-color:rgb(255,0,0)");

