4

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)
Harry Lime
  • 2,167
  • 8
  • 31
  • 53

4 Answers4

3

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()
Harry Lime
  • 2,167
  • 8
  • 31
  • 53
1

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')
    ...
qurban
  • 3,885
  • 24
  • 36
0

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('')
NZD
  • 1,780
  • 2
  • 20
  • 29
-1

Try to use something like

self.pushButton.setStyleSheet("background-color: color")
Mihai8
  • 3,113
  • 1
  • 21
  • 31
  • user1929959 - didn't work, just turned the button black. Of course the answer is similar to 'background-color: xxxx' - that's why I specifically asked - what's the default background color? – Harry Lime May 25 '14 at 15:18