PDA

View Full Version : Disabling ItemIsSelectable for all objects in the graphics scene?



blooglet
30th April 2011, 22:14
In my QGraphicsScene, I put selectable QGraphicsItems in my class. My scene has multiple modes, one of which follows standard selecting behavior. Other modes include a way for the user to paint items.

The other modes don't call QGraphicsScene::mousePressEvent, QGraphicsScene::mouseMoveEvent and QGraphicsScene::mouseReleaseEvent. Yet still, if I double-click an existing item, it is marked as selected.

Any idea as to why this might happen? For a split second I thought about marking every item in the scene as unselectable when the user switches to a non-select mode, but that's a ridiculous workaround and I'm sure that you know how to tackle this quirk properly.

MasterBLB
1st May 2011, 09:40
Your view propagates mouse clicks directly to the items,therefore they become selected.Thats why disabling mouse events for the scene does not work.

blooglet
1st May 2011, 10:25
Aha, that explains a lot... can I easily override this behavior? Or do I have to create my own specialization of a QGraphicsView and override the mouse click events?

MasterBLB
1st May 2011, 11:05
It depends what you want to archieve.If your view does not have to respond at all to mouse clicks then you may instal an event filter on it.But if it does,then you have options:
1.Set appropriate flag on each item (what you want to avoid as I can understand).Thats the option if you're using Qt's graphics items without subclassing them.
2.If you use own items,then you may override mousePressEvent and mouseDoubleClickEvent.You may check inside the state of your scene,and then accept/reject the event

btw-that 'aha' phrase makes me suspicous if you are from Poland?Because I'm Polish,and if it isn't forbidden we may write in Polish.

blooglet
5th May 2011, 12:56
It depends what you want to archieve.If your view does not have to respond at all to mouse clicks then you may instal an event filter on it.
I have to catch all graphics view clicks, so that isn't an option.



2.If you use own items,then you may override mousePressEvent and mouseDoubleClickEvent.You may check inside the state of your scene,and then accept/reject the event
I think this is the best solution to my problem. I'll subclass the graphics view and override these events. I have one question though... I use Qt Creator's GUI designer, so I can't just use my subclassed QGraphicsView, can I? Is there a way to do this properly?


btw-that 'aha' phrase makes me suspicous if you are from Poland?Because I'm Polish,and if it isn't forbidden we may write in Polish.
Sorry to disappoint you, but I'm not. 'Aha' is a pretty universal word: http://en.wiktionary.org/wiki/Aha :)