PDA

View Full Version : GraphicsSceneMouseRelease don't works on top item



QCasper
12th January 2008, 01:06
Hi!

I have two QGraphicsRectItems on a QGraphicsScene. Firts item is parent of second one. On the second item I have installed filter which simply prints message string on press and release event. If filter is installed on the second item, "Release" message will never show. Why? If filter on first, its all OK - both messages are appears.

http://qtnode.net/index.php/pastebin/5386
compilable example - http://www.creobyte.com/tools/releaseevent.zip

QCasper
14th January 2008, 14:57
So, no ideas?

high_flyer
14th January 2008, 15:03
I didn't try it, but I would guess that the problem is that your second item is not part of the scene (see how you allocated it in comparison to the first one, which is IN the scene).
The second item is just an allocated item, belongs to no scene, and the filter filters *scene* events.

QGraphicsItem *firstItem = scene->addRect(QRectF(10.0, 10.0, 80.0, 80.0)); //added to scen
QGraphicsItem *secondItem = new QGraphicsRectItem(QRectF(20.0, 20.0, 60.0, 60.0)); //not in scene

QCasper
14th January 2008, 20:32
No, that is not problem. I was not added secondItem to scene, but I set to it firstItem as its parent:

secondItem->setParentItem(firstItem);
So now secondItem is valid member of scene too.

But even if you are right, why then we can see "Pressed" message? ;)