24

I have to change imgx.x value, should I use JavaScript? Or is there another way?

Row {
    Repeater {
        id:mmm
        model : 10
        Rectangle{
            clip: true
            width: 54
            height: 80
            color:"transparent"
            Image {
                id:imgx
                //x:-160
                //x:-105
                //x:-50
                x:0
                source: "images/tarama_lights.png"
            }
        }
    }
}

2 Answers 2

31

You have to add a property to the direct child of the Repeater (Rectangle in your case) and set it as a target for the property in the internal child (Image in your case). You can then use mmm.itemAt(<index of the element>).<property> = value.

Repeater {
    id:mmm
    model : 10
    Rectangle{
        clip: true
        width: 54
        height: 80
        color:"transparent"
        property int imageX: 0 //adding property here

        Image {
            id:imgx
            x: parent.imageX //setting property as the target
            source: "images/tarama_lights.png"
        }
    }
}

You can then change the property like this:

onPropertyChange: {
    mmm.itemAt(index).imageX = newValue //the index defines which rectangle you change
}
0
8

itemAt is not required to set it as a target for the property in the internal child (Image in your case).

You can have your code as it is and instead of:

onPropertyChange:
{
    //the index defines which rectangle you change
    mmm.itemAt(index).imageX = newValue
}

use this:

onPropertyChange:
{
    //the index defines which rectangle you change
    mmm.itemAt(index).children[0].x = newValue
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.