PDA

View Full Version : QGraphicsItem doesn't inherit QObject?



xyzt
22nd March 2008, 21:31
in the documentation there's a sample that inherits both QObject and QGraphicsItem. Deoesn't QGraphicsItem inherits QObject? I looked at the Qt Assistant but it doesn't give info about that.



class Mouse : public QObject, public QGraphicsItem
{
Q_OBJECT

public:
Mouse();

QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);

protected:
void timerEvent(QTimerEvent *event);

private:
qreal angle;
qreal speed;
qreal mouseEyeDirection;
QColor color;
};

wysota
22nd March 2008, 21:35
No, QGraphicsItem doesn't inherit QObject. It would be too heavy then.

DmitryNik
26th September 2011, 09:09
And what about signals and slots? How we can emit signals and connect them to slots?
Standard QObject::connect will not work. At least it doesn't work in my project, when I try to send the signal from the item to QWidget(every time I've got doesn't match -error).

wysota
26th September 2011, 09:22
Signals and slots require QObject legacy. You can use QGraphicsObject for custom items or subclass existing graphics item classes and derive them from QObject as well.

DmitryNik
26th September 2011, 09:30
Thank you. I guess, it's only way for getting signals and doing the project in a right way.

wysota
26th September 2011, 09:43
No, it's not the only way. You can have a separate controller object that will emit signals on behalf of your items. Then you don't have to modify the item classes and they will remain to be light as you'll only have one object that emits signals for all your items.

DmitryNik
26th September 2011, 14:59
Oh, I didn't consider that at all. Thank you once again for helping. I need to try your advice.