Time for action – Property binding

QML is much more powerful than simple JSON. Instead of specifying an explicit value for a property, you can use an arbitrary JavaScript expression that will be automatically evaluated and assigned to the property. For example, the following code will display "ab" in the label:

Label {
    text: "a" + "b"
    //...
}

You can also refer to properties of the other objects in the file. As we saw earlier, you can use the textEdit variable to set relative position of the label. This is one example of a property binding. If the value of the textField.bottom expression changes for some reason, the anchors.top property of the label will be automatically updated with the new value. QML allows you to use the same mechanism ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.