PDA

View Full Version : how not ta clear the selection on QGraphicsScene right mouse press event



anarky
16th August 2011, 07:19
Hi,

I'm trying to implement the following behavior in my class that inherit QGraphicsScene.

I'd like to display a context menu on right click (that part is pretty straightforward) wherever the user clicked on the scene (i.e. even on plain background) but whose content depend on the currently selected items.

I've reimplemented QGraphicsScene::contextMenuEvent, but in this method, the list of selected items is always empty. This is due to the fact that just before the ContextMenuEvent, there is a MousePressEvent that triggers clearSelection().

I've looked at the source of QGraphicsScene and it seems to me I can either completely ignore the events by reimplementing mousePressEvent and not forwarding the event to QGraphicsScene (and thus loose all the mouse grabbing support I'd like to keep) or I can accept the selection clearing.

Is there a possibility I didn't see to keep the mouse grabbing support ben handle selection manually ?

Regard,
Julien

Lendrick
5th September 2012, 03:22
Solution here:

http://www.qtcentre.org/threads/36953-QGraphicsItem-deselected-on-contextMenuEvent