Harry Lime
Harry Lime

Reputation: 2217

pyQt QPushButton colour

Writing in Python 2.7 using pyQt 4.8.5: What is the default background colour of a pyQt QPushButton widget? I am able to set the colour green but not return it to the default colour. A snap shot of what I mean:

enter image description here

The function responsbile for this:

def StartTransmit(self):
        self.ui.Transmit.setStyleSheet("background-color: green")**
        # self.ui.Transmit.setStyleSheet("background-color: DEFAULT <later on>")
        self.number = random.randint(1,10)
        self.ui.lcd.display(self.number)
        self.timer.start(1000)

Upvotes: 4

Views: 12699

Answers (4)

NZD
NZD

Reputation: 1970

By default the widgets use the standard stylesheet of your system (Mac, Windows, GTK).

You can set a new stylesheet (to overrule the original one) using the call your are already using:

self.ui.Transmit.setStyleSheet('your-stylesheet')

If you want to revert to the original stylesheet use an empty stylesheet:

self.ui.Transmit.setStyleSheet('')

Upvotes: 0

qurban
qurban

Reputation: 3945

By default there is no styleSheet on the widgets. You can check it by just printing the styleSheet of any widget.

print self.pushButton.styleSheet()

Will print an empty string. To set the default color of a widget just set the background color to None

self.pushButton.setStyleSheet('background-color: None')

This way you can restore the default background color of any widget.

Edit

In your case, add the following code:

def stopTransmit(self)
    ...
    self.ui.Transmit.setStyleSheet('background-color: None')
    ...

Upvotes: 1

Harry Lime
Harry Lime

Reputation: 2217

The answer is 'light gray', example:

def StartTransmit(self):
    self.ui.Transmit.setStyleSheet("background-color: green")
    self.timer.start(1000)

def StopTransmit(self):
    self.ui.Transmit.setStyleSheet("background-color: light gray")
    self.timer.stop()

Upvotes: 3

Mihai8
Mihai8

Reputation: 3147

Try to use something like

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

Upvotes: -1

Related Questions