Skip to Content
Game Programming Using Qt Beginner's Guide
book

Game Programming Using Qt Beginner's Guide

by Witold Wysota, Lorenz Haas
January 2016
Beginner
512 pages
12h 35m
English
Packt Publishing
Content preview from Game Programming Using Qt Beginner's Guide

Widgets inside Graphics View

In order to show a neat feature of Graphics View, have 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);
QGraphicsScene scene;
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 the proxy widget by calling addWidget(). The ownership of the spin box isn't transferred, but when QGraphicsProxyWidget gets deleted, it calls delete on all assigned widgets. We thus do not have to worry about that ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Programming using Qt 5 Beginner's Guide - Second Edition

Game Programming using Qt 5 Beginner's Guide - Second Edition

Pavel Strakhov, Witold Wysota, Lorenz Haas
Programming with Qt, 2nd Edition

Programming with Qt, 2nd Edition

Matthias Kalle Dalheimer

Publisher Resources

ISBN: 9781782168874Supplemental Content