Prevent QML Property Bindings when QML object isn't visible?

谁说胖子不能爱 提交于 2021-02-07 06:53:15

问题


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.

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: visible ? tracking.location(index).x : 0

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


回答1:


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
}



回答2:


You can also use Loader{} and set active property to false. This will disable the whole item.



来源:https://stackoverflow.com/questions/32506359/prevent-qml-property-bindings-when-qml-object-isnt-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!