January 2016
Beginner
512 pages
12h 35m
English
So let's alter the Player class to use QObject:
class Player : public QObject, public QGraphicsPixmapItem {
Q_OBJECTAll you have to do is to add QObject as a base class and add the Q_OBJECT macro. Now you can use signals and slots with items too. Be aware that QObject must be the first base class of an item.
If you want an item that inherits from QObject and QGraphicsItem, you can directly inherit QGraphicsObject. Moreover, this class defines and emits some useful signals such as xChanged() when the x coordinate of the item has changed or scaleChanged() when the item is scaled.
A word of warning: Only use QObject with items if you really need its capabilities. QObject adds a ...