Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyQt QPushButton Background color

Tags:

python

pyqt4

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.

like image 312
Trying_hard Avatar asked Dec 18 '13 20:12

Trying_hard


2 Answers

You can change the style of the button:

self.pushButton.setStyleSheet("background-color: red")

It's like CSS.

like image 106
Alvaro Fuentes Avatar answered Sep 17 '22 12:09

Alvaro Fuentes


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)");
like image 43
AB Bolim Avatar answered Sep 20 '22 12:09

AB Bolim