Setting color of checked toggle button
My first foray into Qt land using python and pyqt. I've created a toggle button and I'm able to set its unchecked colors:
Code:
self.DCButton.setStyleSheet("color: black; background-color: red;")
My problem is setting the button color when its "checked":
Code:
self.
DCButton.
setStyleSheet(QPushButton#DCButton:checked {"color:black; background-color: green;}")
doesn't work. I'm sure this is a simple syntax problem.
TIA
Re: Setting color of checked toggle button
Python should be telling you this is an error:
Code:
self.
DCButton.
setStyleSheet(QPushButton#DCButton:checked {"color:black; background-color: green;}")
try:
Code:
self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color:black; background-color: green;}")
Re: Setting color of checked toggle button
Thanks for the reply and sorry for the typo. I've moved the quote to the correct spot in the call, but my problem persists. If I just use the first line, the button reacts correctly (although it uses the default color when checked). When I include the second line, the button reverts to its default colors and behavior:
Code:
self.DCButton.setStyleSheet("color: black; background-color: rgb(3,100,226);")
self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color: black; background-color: green;")
Re: Setting color of checked toggle button
Have a look at the note regarding styling the background of a QPushButton Qt Style Sheets Reference
Code:
QPushButton#DCButton:checked {color: black; background-color: green; border: none; }