[Qt-qml] Set custom property in onChildrenChanged?
michael.brasser at nokia.com
michael.brasser at nokia.com
Mon Nov 1 04:32:27 CET 2010
On 31/10/2010, at 3:11 AM, ext Charley Bay wrote:
>>> charley spaketh:
>>> <snip, set custom property in "onChildrenChanged">
>
>> Michael respondeth:
>> Yes, it should work <snip>
>
> Yes, it works, it was my error. What I'm doing is a little
> more complicated, and there was enough obfuscation
> for me to confuse myself. ;-)
>
> I now have something that "works", but I want to get
> opinions on whether my solution is "stupid" or "best practice".
>
> After further investigation, here's what's going on:
>
> - I create a "myParent" Item{}
> - I create "child" items that are not yet parented to my "myParent"
> - I explicitly parent the child items with "{ parent: myParent }"
>
> <snip>
>
> ?COMMON_CASE: Rich application-specific QML element
> with (hard-coded) internal children, but which *also* manages
> transient (child) elements that are periodically re-parented
> among different QML elements.
>
> For example, this is the common case for any QML element
> that performs layout upon its children. Because QML is
> OUTSTANDING for such dynamic re-parenting (through
> its use of states and transitions), I'd assume many applications
> want to iterate "transient" children separate from "hard-coded"
> children.
>
> SUMMARY QUESTION: What is best practice to separately iterate
> "transient" children from "hard-coded" children?
One alternative might be to add a level of indirection. Rather than "parent: myParent":
* Have a function addChild() on myParent, that could take care of the parenting and also add the items to a separate, transient-child-only list
* Use property aliasing and an "inner" wrapper element to contain all the transient children (e.g. default property alias myChildren: innerElement.children). This is probably more applicable in the static case though (see e.g. Flickable, which has a default property of flickableChildren, which reparents its items to the contentItem).
Regards,
MIchael
More information about the Qt-qml
mailing list