O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Ignoring transformations

If you try to zoom in on our custom rectangles scene (for example, by calling view.scale(4, 4)) , you will note that everything is scaled proportionally, as you would expect. However, there are situations where you don't want some elements to be affected by scale or other transformations. Qt provides multiple ways to deal with it.

If you want lines to always have the same width, regardless of the zoom, you need to make the pen cosmetic:

QPen pen = parent->pen();
pen.setCosmetic(true);
parent->setPen(pen);

Now, the rectangles will always have lines with one-pixel width, regardless of the view's scale (anti-aliasing can still blur them, though). It's also possible to have cosmetic pens with any width, but using them ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required