hl037_
hl037_

Reputation: 3907

How to forward properties of a child component?

When writing a wrapper around some components, for example :

MyComponent.qml

ColumnLayout{
    ListView{
        id: listview
    }
}

Is it possible to expose all the properties from a child (listview here) without typing by hand all the aliases ?

So that I can do something similar to what the following would do if it was allowed :

ColumnLayout{
    MyComponent{
        listview.model: ListModel{  // Here
        }
    }
}

(Either by forwarding them, either by defining a property that point to listview (I tried, it does not seems to work...), or any other way that permit to bind a property from listview as I would do if I was defining a ListView)

Upvotes: 0

Views: 737

Answers (1)

JarMan
JarMan

Reputation: 8277

You just need to alias the id of the object you want to expose. So in MyComponent.qml, you can do this:

ColumnLayout{
    property alias listview: listview
    ListView{
        id: listview
    }
}

Then you can access it from other objects:

ColumnLayout{
    MyComponent{
        listview.model: ListModel{
        }
    }
}

Upvotes: 1

Related Questions