PDA

View Full Version : subclassing QGraphicsItem, QGraphicsPixmapItem



rogerholmes
26th August 2009, 15:27
can someone point me in the right direction to find COMPLETE examples of subclassing. I have not made this request here because i did not want to look like an idiot... but i can not find the docs to show me how to do this.



this works for me

QGraphicsItem *item;
item=this->scene()->addPixmap(pixmap);

i am trying to sub class QGraphicsItem.
my subclass does not work :
myGraphicItem *item;
item=this->scene()->addPixmap(pixmap);

error ! cannot convert QGraphicsPixmapItem* to myGraphicsItem* in assignment.

wysota
26th August 2009, 15:45
It won't work that way. The method returns a QGraphicsPixmapItem so you can only assign it to QGraphicsPixmapItem or its ancesstor (QGraphicsItem) pointer.

If you want to subclass QGraphicsItem or one of its subclasses, you need to add the item to the scene in a different manner:

myGraphicsItem *item = new myGraphicsItem;
scene()->addItem(item);

rogerholmes
26th August 2009, 22:02
Thanks Wysota,

I will try it that way, i need to be able to change the boundingRect. Do you know of a place i can research the subclassing of Qt classes.

roger

wysota
26th August 2009, 23:12
Qt is ANSI C++ compliant so everything that applies to subclassing in C++ applies to subclassing Qt classes as well.