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

Time for action – Using child items

Let's try to make an item containing multiple children. We want to create a rectangle with a filled circle in each corner and be able to move and rotate it as a whole, like this:

First, you need to create a function that creates a single complex rectangle, by using the following code:

QGraphicsRectItem *createComplexItem(    qreal width, qreal height, qreal radius) { QRectF rect(-width / 2, -height / 2, width, height); QGraphicsRectItem *parent = new QGraphicsRectItem(rect); QRectF circleBoundary(-radius, -radius, 2 * radius, 2 * radius); for(int i = 0; i < 4; i++) { QGraphicsEllipseItem *child = new QGraphicsEllipseItem(circleBoundary, ...

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