Property groups

Before we discuss anchors, let's talk about property groups in general. This is a new concept introduced in QML. Property groups are used when there are multiple properties with a similar purpose. For example, the Label type has a number of properties related to the font. They can be implemented as separate properties; consider the following example:

Label {    // this code does not work    fontFamily: "Helvetica"    fontSize: 12    fontItalic: true }

However, such repetitive code is hard to read. Luckily, font properties are implemented as a property group, so you can set them using the group notation syntax:

Label {    font {        family: "Helvetica"        pointSize: 12        italic: true     }}

This code is much cleaner! Note that there is no colon character ...

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.