当 QML 对象不可见时防止 QML 属性绑定? [英] Prevent QML Property Bindings when QML object isn't visible?

查看:31
本文介绍了当 QML 对象不可见时防止 QML 属性绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有大量属性绑定的 QML 应用程序:数百个对象被跟踪并以不同的形式显示,例如 Qt3D/QCanvas.

I'm working on a QML application that has a lot of property bindings: hundreds of objects are tracked and displayed in different forms like Qt3D/QCanvas.

当我在应用程序的单独页面上时,这些 x/y 位置和相对大小的属性绑定仍在发生.我怎样才能阻止他们?我知道我可以根据它们是否可视来绑定属性,但这是很多不必要的代码:

When I'm on a separate page of the application those property bindings for x/y locations and relative sizes are still happening. How can I stop them? I know I could bind the properties based on whether they're visual or not but that is a lot of unnecessary code:

x:可见?tracking.location(index).x : 0

x: visible ? tracking.location(index).x : 0

我将不得不包装大量这样的绑定.还有其他解决方案吗?

I would have to wrap a ton of bindings like that. Any other solutions?

推荐答案

可以使用绑定 元素.您可以指定目标、属性、值和条件来激活绑定.

You can use the Binding element. You can specify target, property, value and condition to activate the binding.

Binding on x {
    value: tracking.location(index).x
    when: visible
}

这篇关于当 QML 对象不可见时防止 QML 属性绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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