PDA

View Full Version : access to event when an object is dinamically created



jano_alex_es
9th February 2010, 09:25
Hi,

it's strange, but I have a very basic question but I don't find the answer :S

if you create something, like for instance:


QGraphicsPixmapItem* pPixmap = new QGraphicsPixmapItem();

How I can access to its events? In my case, I would like to execute code when painting is called, so far I've subclased the paint event but for the first time I'm not subclassing anything.

thanks!

high_flyer
9th February 2010, 10:14
You have two options:
1. Subclass QGraphicsPixmapItem and override the event methods you want
2. Install an event filter on the object - see http://doc.trolltech.com/4.6/qobject.html#installEventFilter on how to do it.

jano_alex_es
9th February 2010, 10:17
thanks! that was what I was searching for.

jano_alex_es
9th February 2010, 16:31
uop, sorry, I just have seen now that a QGraphicsItem is not a QObject, so install the event filter is not allowed.

the only thing I see is QGraphicsItem::installSceneEventFilter, but I need to filter the events of one QGraphicsPixmapItem in one QObject, not one graphics item into another.

Am I wrong? or do I have any other possibility than subclass?

high_flyer
9th February 2010, 17:08
Sorry, I forgot that QGrphicsItems are not QObjects.
I think the easiest way would be to subclass QGraphicsPixmapItem and deal with the events there.