How to force a style sheet recalculation
-
IIRC, calling buton->setStyleSheet("/* /"); should be enough to clear the caches for this widget and force a recomputation of the style.
(Notice "/ */" and not "" in order to avoid an empty stylesheet that would be ignored)@ogoffart you're my hero, I had discovered a weird effect on Qt6.9.1 (and later also on some older Qt6 versions), sending an empty or invalid string to setStyleSheet() didn't always clear the previously set stylesheet, but your proposed solution perfectly works, always! Thanks man!
-
The solution from @ogoffart works for me, too.
setStyleSheet() in >6.9.1 doesn't work for me to refresh the stylesheet. I use widget.setStyleSheet(widget.styleSheet()), but that isn't reliable. @WolfgangGriech also describes this.
Perhaps this should be reported as bug?It's been reported and fixed for 6.10. -
The solution from @ogoffart works for me, too.
setStyleSheet() in >6.9.1 doesn't work for me to refresh the stylesheet. I use widget.setStyleSheet(widget.styleSheet()), but that isn't reliable. @WolfgangGriech also describes this.
Perhaps this should be reported as bug?It's been reported and fixed for 6.10.@larsmaxfield
FWIW, (I believe) I recall in some Qt 5 version years ago in order to get it reliably to count as a change I had to/ended up doing:temp = widget.styleSheet(); widget.setStyleSheet(""); widget.setStyleSheet(temp);
-
@larsmaxfield
FWIW, (I believe) I recall in some Qt 5 version years ago in order to get it reliably to count as a change I had to/ended up doing:temp = widget.styleSheet(); widget.setStyleSheet(""); widget.setStyleSheet(temp);
Maybe even
That might force the style(sheet) to update too.
But usually the widget should do this when a new style(sheet) is applied.