Are Qt's stylesheets really handling _dynamic_ properties?

mdcl picture mdcl · Oct 20, 2009 · Viewed 9.7k times · Source

Is Qt's dynamic properties really so dynamic with stylesheets?

I have the basic example from stylesheets and dynamic properties:

/*stylesheet:*/
*[field_mandatory="true"] { background-color: "yellow";}

And I have this happening at runtime somewhere in the code:

/*code:*/
myWidget->setProperty("field_mandatory", field->isFilled() );

Nothing changes in UI, when this property is changed at runtime.

Does anyone have ideas what must be done to update Qt's stylesheet engine when changing properties, or is it even capable handling these kinds of cases?

Btw. I'm using Qt 4.4

Answer

Jason picture Jason · Sep 29, 2010

Qt has the following recommendation in their FAQ:

style()->unpolish(theWidget);
style()->polish(theWidget);

They also say you can reset the stylesheet by doing the following but it is more expensive:

setStyleSheet(styleSheet());