Yay! Found the solution.
It’s actually pretty simple.
When creating an object with Loader you can add properties the same way you do with all other objects.
Loader {
property color aNewProperty: "#ff8080"
sourceComponent: theComponentToCreate
}
I wish this had been mentioned in the documentation to the Loader Element.
To be complete, here are the working sources.
main.qml:
import QtQuick 2.0
Rectangle {
width: 360; height: 360
color: "aliceblue"
Rectangle {
anchors.centerIn: parent
width: 300; height: 300
border {color: "black"; width: 1 }
Container {
anchors.margins: 1
aThing: Rectangle {
width: 100; height: 100;
color: Qt.darker(parentColor, 1.5)
border.color: "black"
border.width: 1
}
}
}
}
Container.qml:
import QtQuick 2.0
Rectangle {
id: root
property color theColor: "lightsteelblue"
property Component aThing: Item { }
anchors.fill: parent
color: theColor
Loader {
property color parentColor: root.theColor
anchors.centerIn: parent
sourceComponent: aThing
}
}
Kudos to myself.
↧