21

以下のコードについて、imgx 要素のプロパティを変更する方法を教えてください。javascript を使用して imgx.x の値を変更する必要があります。それとも他に方法はありますか?qt ドキュメントを検索しますが、役に立ちません。ありがとう。

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"
            }
        }
    }
}
4

2 に答える 2

28

Repeater の直接の子 (この場合は Rectangle) にプロパティを追加し、内部の子 (この場合は Image) のプロパティのターゲットとして設定する必要があります。を使用できます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"
    }
  }
}

次に、次のようにプロパティを変更できます。

onPropertyChange: {
  mmm.itemAt(index).imageX = newValue //the index defines which rectangle you change
}
于 2012-11-07T15:20:03.307 に答える