Placing child elements in a component



  • Is there some way in a component to specify where should the child items be placed?

    I mean something like:

    main.qml:
    @import Qt 4.7

    MyComponent {
    Image { id: coolpic; source: "pic.jpg" }
    }@

    MyComponent.qml:
    @import Qt 4.7

    Rectangle {
    border.color: "black"

    Rectangle {
        color: "white"
        anchors.margins: 3
    
        // placeholder for the children (e.g. the coolpic Image element)
    }
    
    // some other items here
    

    }@



  • try this

    @
    import Qt 4.7

    default property alias content: content.children

    Rectangle {
    border.color: "black"

    Rectangle {
        id: content
        color: "white"
        anchors.margins: 3
    
        // placeholder for the children (e.g. the coolpic Image element)
    }
    
    // some other items here
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.