开发者

Adding elements at runtime

开发者 https://www.devze.com 2023-02-18 19:28 出处:网络
How can I add an element to any view at runtime? for example, when s开发者_JAVA技巧ome signal is fired, the application should add a rectangle to a specific row.

How can I add an element to any view at runtime?

for example, when s开发者_JAVA技巧ome signal is fired, the application should add a rectangle to a specific row.

Thanks,


Using Component should do the trick.

MySignalSource {
    Row {
        id: myRow
        anchors.fill: parent
    }

    Component {
        id: myRectComp
        Rectangle {
            width: 50
            height: 50
        }
    }

    onSignalFired: {
        var rect = myRectComp.createObject(myRow)
        rect.color = "black"
    }
}

Not tested, but it should work like that.

0

精彩评论

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