Issue
When I have a QPushButton that is pressed with the toggle option. How do I set the background color of the button to be another color other than black? This code attempts to use StyleSheets to do so, but it remains black.
light_label = QtWidgets.QPushButton(light)
light_label.setCheckable(True)
light_label.toggled.connect(partial(self.light_label_event, light))
light_label.setStyleSheet('QPushButton::checked{background:rgb(255, 0, 0); }')
Solution
You have to use the pseudo-state checked:
import sys
from PySide import QtGui
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
button = QtGui.QPushButton("Hello world")
button.setCheckable(True)
button.setStyleSheet("""
QPushButton {background:rgb(65,66,66); color: white;}
QPushButton::checked{background:rgb(255, 0, 0); color: white;}
""")
button.show()
sys.exit(app.exec_())
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.