Question
I need to change the background image of a QPushButton
when its state is pressed. I tried with this css:
QPushButton { background: transparent; border: none;}
QPushButton:pressed { image: url(\mypath\settings_press.png); }
but a runtime I got the following error:
Could not parse stylesheet of widget
Any idea?
Solution
All of the examples of Qt stylesheets I've seen use UNIX style paths, so your CSS should look like:
QPushButton { background: transparent; border: none;}
QPushButton:pressed { image: url(/mypath/settings_press.png); }
Also, URLs for Qt stylesheets need to be a relative path to a Qt resource like:
QPushButton:pressed { image: url(':images/settings_press.png') }
or absolute paths like:
QPushButton:pressed { image: url('/usr/share/icons/crystalsvg/settings_press.png') }
I would go the resource route unless you can absolutely guarantee the install path of your image.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow