Why does all selected QGraphicsItem not receive mouseMove event?

928 views Asked by At

I have several QGraphicsItem objects on my custom GraphicsScene. They have different custom types, so some of them have to handle MouseMove event in one way, and other in different way. When I select some of them and then move selected items only the item that is under the mouse cursor receive MouseMove event but other items does not. I have to make some additional actions in MyCustomItemClass::mouseMoveEvent when moving is started. So why does the other items not receive the event?

2

There are 2 answers

7
Bowdzone On BEST ANSWER

From your description I would not handle these actions in MyCustomItemClass::mouseMoveEvent because this is only executed when the mouse moves on top of that particular item as you already stated.

Instead I'd subclass the mouseMoveEvent in the scene to check which items are selected and execute the related method in these items. Of course you have to be careful to only move them relatively to their original position according to the relative mouse movement.

2
TheDarkKnight On

If you want to select a group of items and then move them all at once, you can add them to a QGraphicsItemGroup during the select and then move the group as a single object, which will move all the items in the group.