开发者

QtQuick, QML - How do I copy one Item's child to another?

Using QML, I'd like to copy one Item's child to another. Here's what I tried:

Item
{
    id: itemOne;
    Component.onCompleted: {  children.push(itemTwo.children[0]);  }
}

Row
{   // has many children

    id: itemTwo;
    Imag开发者_如何学Pythone {}
    Image {}
    Image {}
}

I get an error like: TypeError: Result of expression 'children.push' [undefined] is not a function. So how do I copy children over then? I'd appreciate any advice

-tricky


An item cannot be copied because it cannot have multiple parents.

Instead of copying, try creating the new child dynamically, as described in here, and pass 'itemTwo' as the id for the parent of the new child.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜