View Full Version : 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:
self.DCButton.setStyleSheet("color: black; background-color: red;")
My problem is setting the button color when its "checked":
self.DCButton.setStyleSheet(QPushButton#DCButton:c hecked {"color:black; background-color: green;}")
doesn't work. I'm sure this is a simple syntax problem.
TIA
ChrisW67
26th July 2010, 01:31
Python should be telling you this is an error:
self.DCButton.setStyleSheet(QPushButton#DCButton:c hecked {"color:black; background-color: green;}")
try:
self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color:black; background-color: green;}")
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:
self.DCButton.setStyleSheet("color: black; background-color: rgb(3,100,226);")
self.DCButton.setStyleSheet("QPushButton#DCButton:checked {color: black; background-color: green;")
ChrisW67
26th July 2010, 02:23
Have a look at the note regarding styling the background of a QPushButton Qt Style Sheets Reference (http://doc.trolltech.com/4.6/stylesheet-reference.html#qpushbutton-widget)
QPushButton#DCButton:checked {color: black; background-color: green; border: none; }
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.