开发者

Are Qt's stylesheets really handling _dynamic_ properties?

开发者 https://www.devze.com 2022-12-09 13:35 出处:网络
Is Qt\'s dynamic properties really so dynamic with stylesheets? I have the basic example from stylesheets and dynamic propert开发者_如何学Pythonies:

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

I have the basic example from stylesheets and dynamic propert开发者_如何学Pythonies:

/*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


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());


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.


The following works for me to ensure a proper restyling of the widget:

myWidget->setStyle(QApplication::style())

Forcing a recomputation of the stylesheets as proposed by mdcl did not work for me. I am using Qt 4.5.3.


I tried this too with no luck, and when I found the following text in the documentation, I gave up. See The Style Sheet Syntax:

Warning: If the value of the Qt property changes after the style sheet has been set, it might be necessary to force a style sheet recomputation. One way to achieve this is to unset the style sheet and set it again.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号