Displaying a QGraphicsScene inside a QGraphicsView and a custom view simultaneously based on different rules?
-
I am having some trouble formulating my intent. Basically I want to have an ordinary QGraphicsScene that is displayed inside an ordinary QGraphicsView, however I also want to be able to display the content of the scene inside a custom view, where items are displayed based on their relationship rather than a coordinate system scene.
Like for example I may have an item A that is very far on the coordinate system from an item B, but A is the parent of B, so if I select A inside the custom view I need B to be listed under A, which is centered since it has the focus. I know the scene is the parent of items but in my case I need to have deeper parenting for items.
The custom view follows very simple logic. The item that has focus/ is selected is always in the center, its parents (may be multiple) on top of it, its children under it, related items on the left, siblings on the right. If another item is selected, the custom view is rearranged again.
Which is the way to go? Do it keep the custom position as a copy to override the position of items based on item relations and move items around, restoring the custom position from the copy to revert back to the original locations of items. Or is there a way to implement a custom view that can work directly with QGraphicsScene?
-
Hi,
If I needed to do what you suggest, I'd maintain two scenes and views where the second scene is the one you wanted to display child-parent relationships. Then in the second scene add the children in the location you want, directly under their parents. You'll need to manage adding and removing of the child QGraphicsObjects/Widgets as you select each parent in the first scene.
Hope I've made that clear and hope it helps.
Simon ;O) -
I get your point, will try it out. My main concern of using two scenes was the scene acts as a manager for all objects, so the problem rises with how two scenes will share the same objects. My current approach is creating temporary widgets that use the data members from the graphic items that are related to the item in focus and displaying in a regular widget, and for now it seems to work fine, but will give your suggesting a go.
-
In order for two scenes sharing the same object, I suggest looking at trying to split the data for the objects from the graphicsItem; create a separate object, based off QObject, with the info you want and provide signals that when that object changes, it updates the relevant items in the two scenes.
You could also look at the model / view / controller design pattern to see where I'm going with that idea.