Attached properties to access parent Loader from loaded Item?
-
Are any properties attached to the item loaded by a
Loader
that would facilitate access of the parentLoader
properties from the loaded Item?As an example, I would like to dismiss a loaded item on a button press. The item is loaded within the scope of the Loader so Loader properties can be accessed directly. Thus I can set
sourceComponent = undefined
within the loaded Item and that works. But what if I wanted to set the Loader opacity to 0 for instance? I cannot directly set the opacity (unlikesourceComponent
) because that applies to the opacity of the specific QML element within the loaded Item. I can doloaderName.opacity = 0
and that works, but that ties the Item to a specific Loader.Just like a
ListView
is accessible within its delegate, is there anything analogous forLoader
? If not, is there any idiomatic way to access parent Loader properties from a loaded Item? -
It looks like the easiest way to accomplish this is to inject a property into the loaded Item by simply defining it on the Loader itself:
Loader { id: myLoader anchors.centerIn: parent property alias loaderOpacity: myLoader.opacity ... }
Now
loaderOpacity
can be used to change parent Loader opacity from the loaded Item.