[SOLVED] Load Component on signal
QML and Qt Quick
5
Posts
2
Posters
1.3k
Views
1
Watching
-
Hi everyone,
I have been trying to create a component when a signal is emitted (for instance on the onClicked of a MouseArea, a Rectangle is fully created ). I have been trying to use Loaders but without success.
If anyone of you has any idea on the matter, I would really appreciate it.
Thanks -
Hi,
Using Loader it should work.
Can you show how you were trying to load through Loader ? -
You are using the Loader incorrectly. One of the correct way is to load the component for Loader onClick like this,
@
Item
{
id: root
width: 400
height: 400
MouseArea
{
anchors.fill: parent
onClicked: loader.sourceComponent = myRectangle
}Loader { id: loader anchors.centerIn: parent } Component { id: myRectangle Rectangle { height: root.height/2 width: root.width / 2 color: "blue" } }
}
@Have a look at "Loader":http://qt-project.org/doc/qt-5/qml-qtquick-loader.html. There are many examples of how to use it.