Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 505
Slayer0606 Avatar asked Sep 10 '15 15:09

Slayer0606


People also ask

What is property binding in QML?

Property bindings are a core feature of QML that lets developers specify relationships between different object properties. When a property's dependencies change in value, the property is automatically updated according to the specified relationship.

How do you use property in QML?

A property is an attribute of an object that can be assigned a static value or bound to a dynamic expression. A property's value can be read by other objects. Generally it can also be modified by another object, unless a particular QML type has explicitly disallowed this for a specific property.


2 Answers

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
}
like image 182
dtech Avatar answered Oct 13 '22 23:10

dtech


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

like image 2
vpicaver Avatar answered Oct 13 '22 23:10

vpicaver