Search code examples
qtstylesheet

Are Qt's stylesheets really handling _dynamic_ properties?


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


Solution

  • I found a quick, although a bit hackish, way to update widget's styling.

    myWidget->style()->unpolish(myWidget);
    myWidget->ensurePolished();
    

    Doing this after changing properties keeps correlation between property data and UI.