PDA

View Full Version : QGraphicsScene & QGraphicsView design decisions



hayzel
26th December 2014, 14:27
Hi,
I really need help concerning my program using QGraphicsScene/View.
My program is a cad-like software that edits some myItem derived QGraphicsItems, outputs some non-editable/non-selectable QGraphicsItems as output, and uses some control QGraphicsItems (node handles).

My main problem is the QGraphicsScene::selectionChanged() signal behaviour.
I want my program to control when selectionChanged can be happen. For example I have a mode that selects editable objects and applies different actions onto them. BUT there are some modes also that depend on user/mouse actions and they have to leave selection unchanged.
So my first question is: What is the correct / clean way to stop QGraphicsScene::selectionChanged and keep selectedItems frozen? Any suggestions are welcomed.
I tried to set a flag isSelectionChanging in my scene re-implementation , and use it to my base myItem::mousePress/Release/Move functions to not call the base class QGraphicsItem::mousePress/Release/Move when this flag is on. The thing is that it doesn't work because selectionChanged is called when the user clicks on an empty position of the screen and the current selection is cleared.

Added after 28 minutes:

I thought another solution. I can create a huge QGraphicsItem covering all the scene that has an empty paint() function and boundingRect() all over the scene, and has the biggest Z value and can be selected. So all the user/mouse input will go to it. I then will have to make my own myselection mechanism to update whenever I choose with the mouseEvents of this item, and make my own myselectionChanged signal emit.
I did not try the above, cause I have concerns on how QGraphicsScene/View will treat this item and if there will be any speed issues on updating, colliditing etc.
Any thoughts?

wysota
26th December 2014, 14:32
In my opinion you should be managing the selection yourself. You can restore the old selection when you detect it shouldn't be changing.

hayzel
26th December 2014, 19:05
In my opinion you should be managing the selection yourself. You can restore the old selection when you detect it shouldn't be changing.

I was too frustrated messing around with custom tricks to make the selection system work as I needed to work, and I missed the obvious answer. I wrote a simple selection system over my re-implementation of QGraphicsScene according to my needs, and all work fine. Thanks.