I'm trying to support theming for my application, and I'm coming across a problem where I have to change icons based on the state of the QPushButton (default, hover, pressed, etc.). Here is what I use to set the icon for a QPushButton:
QPushButton#playButton {
qproperty-icon: url(":/light/icons/play_light.png");
}
Because the hover state uses a background that requires an icon from my dark theme, I tried to change it to the other using this:
QPushButton#playButton:hover {
qproperty-icon: url(":/dark/icons/play_dark.png");
}
When I do this, the play_light.png
displays as it should, but it doesn't change to play_dark.png
on state change.
In my Python code, the play button changes to a stop button on playback, so in my style, I set it to that icon using a custom property:
QPushButton#playButton[isPlaying="true"] {
qproperty-icon: url(":/light/icons/stop_light.png");
}
This wouldn't change for me either. So, I found some code online to reset the style for the button, which looks like this:
self.ui.playButton.setProperty('isPlaying', not isEnable)
self.ui.playButton.setStyle(qApp.style())
I don't want to use this workaround for every single button for every single state change. Have you guys ran into this problem before?
Thanks for your time looking at this.