Component and Loader where there's a property alias between the Component Item and the Loader?
-
Hi!
Let's say I have a
Componentthat contains aRadialGradient.Component { id: radGrad RadialGradient { //stuff here } }Now I use a Loader to create it and bind it to a
Rectangle(which is essentially an opacity mask)Rectangle { id: wrecked x:0; y:0; width: 256; height: 256 //LOL! Coder numbers! radius: 32 } Loader { sourceComponent: radGrad anchors.fill: parent // Loader already has a source property - RadialGradient source property is "hidden" source: wrecked // BANG! }As you can see both the
Loaderand theRadialGradienthave asourceproperty and theLoaderproperty, naturally, wins out. So how do I set the source property of the inner item? I can't add a property alias to the inlineComponentbecauseComponent objects cannot declare new properties.Currently the only decent work around I have is this...
Loader ... onLoaded: { item.source = wrecked }But this doesn't "feel" good (should be a bind anyway). I can't write
item.sourceinside theLoadereither.What's a better solution?
Yours,
Matthew -
Hi!
Let's say I have a
Componentthat contains aRadialGradient.Component { id: radGrad RadialGradient { //stuff here } }Now I use a Loader to create it and bind it to a
Rectangle(which is essentially an opacity mask)Rectangle { id: wrecked x:0; y:0; width: 256; height: 256 //LOL! Coder numbers! radius: 32 } Loader { sourceComponent: radGrad anchors.fill: parent // Loader already has a source property - RadialGradient source property is "hidden" source: wrecked // BANG! }As you can see both the
Loaderand theRadialGradienthave asourceproperty and theLoaderproperty, naturally, wins out. So how do I set the source property of the inner item? I can't add a property alias to the inlineComponentbecauseComponent objects cannot declare new properties.Currently the only decent work around I have is this...
Loader ... onLoaded: { item.source = wrecked }But this doesn't "feel" good (should be a bind anyway). I can't write
item.sourceinside theLoadereither.What's a better solution?
Yours,
MatthewHi @kindid and welcome
you can define properties inside your loader component, that than can be accessed by the loaded item/component
something like this:Loader { sourceComponent: radGrad anchors.fill: parent // Loader already has a source property - RadialGradient source property is "hidden" property var wreckedSource: wrecked } Component { id: radGrad RadialGradient { source: wreckedSource } } -
Both work nicely. I will probably go with
Bindingas it means the interface to theItemcontained within theComponentmaintains the same property set as is documented. But the use of aLoaderdefined property is a very interesting use of the dynamic search space from the perspective of theComponentencapsulatedItem. I may have other uses for that - not sure yet!Thank you very much!