[SOLVED] Load Component on signal



  • 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


  • Moderators

    Hi,

    Using Loader it should work.
    Can you show how you were trying to load through Loader ?



  • @
    Item
    {
    id: root
    MouseArea
    {
    anchors.fill: parent
    onClicked:
    Loader
    {
    sourceComponent: myRectangle
    }
    }
    Component
    {
    id: myRectangle
    Rectangle
    {
    height: root.height / 2
    width: root.width / 2
    anchors.centerIn: parent
    color: "blue"
    }
    }
    }

    @


  • Moderators

    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.



  • Tanks :)


Log in to reply
 

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