Tuesday, April 6, 2010

Reuse QML item

In normal Qt application, we use variable to refer same object. But in QML, we refer the object from the other one with identifying QML item in id. For example:
import Qt 4.7

Rectangle {
    width: 200
    height: 200
    Text {
        id: original // identify this item as "original"
        x: 60
        y: 80
        text: qsTr("Hello World")
    }
    Text {
        x: original.x // refer original
        y: original.y + 16 // refer original and calculate
        text: original.text + "!" // refer original and concatenate
    }
}

No comments:

Post a Comment