What just happened?

First, we set a four pixels wide black pen for the painter. Then, we called rect() to retrieve the geometry rectangle of the widget. By calling adjusted(), we receive a new rectangle with its coordinates (in the left, top, right, and bottom order) modified by the given arguments, effectively giving us a rectangle with a 10 pixel margin on each side.

Qt usually offers two methods that allow us to work with modified data. Calling adjusted() returns a new object with its attributes modified, while if we had called adjust(), the modification would have been done in place. Pay special attention to which method you use to avoid unexpected results. It's best to always check the return value for a method—whether it returns a copy ...

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.