Qt 的样式表真的处理 _dynamic_ 属性吗? [英] Are Qt's stylesheets really handling _dynamic_ properties?

查看:24
本文介绍了Qt 的样式表真的处理 _dynamic_ 属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt 的动态属性真的和样式表一样动态吗?

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

在运行时更改此属性时,UI 中没有任何变化.

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

有没有人知道在更改属性时必须做什么来更新 Qt 的样式表引擎,或者它甚至能够处理这些类型的情况?

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?

顺便说一句.我正在使用 Qt 4.4

Btw. I'm using Qt 4.4

推荐答案

我找到了一种快速更新小部件样式的方法,虽然有点笨拙.

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

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

在更改属性后执行此操作可保持属性数据和 UI 之间的相关性.

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

这篇关于Qt 的样式表真的处理 _dynamic_ 属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆