Anti-aliasing

If you look at the result of the previous screenshot, you can probably note that the drawing looks pixelated. This happens because each pixel in a line is completely black, and all the surrounding pixels are completely white. The physical display's resolution is limited, but a technique called anti-aliasing allows you to produce more smooth images with the same resolution. When drawing a line with anti-aliasing, some pixels will be more or less blacker than others, depending on how the line crosses the pixel grid.

You can easily enable anti-aliasing in Graphics View using the following code:

view.setRenderHint(QPainter::Antialiasing);

With the anti-aliasing flag turned on, the painting is done much more smoothly:

However, lines ...

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.