What just happened?

You can see that the rectangle is centered in the window using a centerIn anchor binding that we didn't mention before. This is one of the two special anchors that are provided for convenience, to avoid having to write too much code. Using centerIn is equivalent to setting both horizontalCenter and verticalCenter. The other convenience binding is fill, which makes one item occupy the whole area of another item (similar to setting the left, right, top, and bottom anchors to their respective anchor lines in the destination item).

Instead of setting a solid color for the button, we declared the background to be a linear gradient. We bound a Gradient element to the gradient property and defined two GradientStop elements as ...

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.