Get repeater elements to give them a specific script

  • I have a few rectangles that I created with a repeater. Those rectangle are going to use a mouse area to add actions to each one. But my problem is that I don't know how to give each one a different action ( call different method, or call with specific properties...)
    Does anybody can help me with this ?

    Thank you in advance

  • Hi, do you mean something like this:

    Column {
        anchors.centerIn: parent
        spacing: 4
        Repeater {
            model: 4
            Rectangle {
                id: rect
                width: 100
                height: 100
                color: "black"
                property var func
                MouseArea {
                    anchors.fill: parent
                    onClicked: rect.func()
            onItemAdded: {
                if (index % 2)
                    item.func = function () { console.log("function 1 called."); }
                    item.func = function () { console.log("function 2 called."); }

  • hi @DavidM29,
    On way to do that is passing the index of the clicked rectangle to a function witch will do different things depending on index.
    So in the repeater :

     onClicked: func(index)
    function func(ind){

  • @GPBeta @LeLev
    Thanks for your anwser I believe both solutions could work. I'll try it.

Log in to reply