Css – How to change a QPushButton icon when it has focus

cssqts60

I'm using a QPushButton in an S60 Qt app.

I want the button icon to change when it has focus.

I've tried this…

navButton->setStyleSheet("background-image: url(c:/Data/navArrowsNotSelected.png);");
setStyleSheet("DoubleViewWidget QPushButton:focus {background-image: url(c:/Data/navArrowsSelected.png); border: 2px solid yellow}");

…but the background image doesn't change with focus.

I've also tried other approaches, using QPalette, etc., but can't get this to work.

Is there a way to select a focus style for a widget?

…or is there another way to do this?

Best Answer

You can't set one stylesheet directly on the button, and one on the parent widget. The button one will be prefered. Try this:

 navButton->setStyleSheet("QPushButton { background-color:red; } QPushButton:focus { background-color:blue; }");