0

The specific application is a Tic Tac Doe toy app made of a grid of 9 buttons. The original layout of the buttons is built in Qt Creator, where their large font is established by a styleSheet property.

When a winning row occurs, I want the main app to 'light up' that row of buttons, without it needing to be aware of the buttons' properties that were established in Qt Creator. I want to modify their styleSheets rather than just set them, so that the app retains the buttons' original properties, as well as in addition changing the background colour to green in this case.

Many related questions seem to deal with setting styleSheets, even setting them to different properties if the widget is activated, but not with modifying them from existing settings.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
David Wallace
  • 212
  • 4
  • 12
  • @eyllanesc: The example is a trivial learning exercise but the answer is meant to show how an App can change the properties of a widget established in Qt Creator without needing to know those properties, and yet without destroying them. – David Wallace Apr 07 '17 at 15:36
  • Could be regarded as a duplicate of this question: pyqt-way-to-read-a-widgets-stylesheet – David Wallace Apr 07 '17 at 16:09

1 Answers1

-1

This worked for me:

def highlightButton(self, button):
    currentStyle = button.styleSheet()
    highlightStyle = 'background-color: lightgreen;'
    combinedStyleSheet = 'QPushButton {' + currentStyle + highlightStyle + '}'
    button.setStyleSheet(combinedStyleSheet)
David Wallace
  • 212
  • 4
  • 12