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

Widgets inside Graphics View

In order to show a neat feature of Graphics View, take a look at the following code snippet, which adds a widget to the scene:

QSpinBox *box = new QSpinBox;
QGraphicsProxyWidget *proxyItem = new QGraphicsProxyWidget;
proxyItem->setWidget(box);
scene()->addItem(proxyItem);
proxyItem->setScale(2);
proxyItem->setRotation(45); 

First, we create a QSpinBox and a QGraphicsProxyWidget element, which act as containers for widgets and indirectly inherit QGraphicsItem. Then, we add the spin box to the proxy widget by calling addWidget(). When QGraphicsProxyWidget gets deleted, it calls delete on all assigned widgets, so we do not have to worry about that ourselves. The widget you add should be parentless and must not be ...

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