PDA

View Full Version : Displaying bug with QGraphicsView in QGraphicsView



veiovis
27th July 2014, 12:57
Hello,

I want to display hierarchical statecharts with QGraphicsViews.
So every State can contain substates which in turn can i have also substates and so on.
Each state displays its substates in a QGraphicsView, so there are QGraphicsViews in QGraphicsView in QGraphicsView...
Each State inherits from QGraphicsItem and contains a QGraphicsProxyWidget which contains a Widget with a QGraphicsView.

I tested it with a top level state, that contains two substates.
Now comes the strange part:
The first inserted substate is displayed perfectly fine, but the second substate seems to be confused of who its parent is:
The visibility of the 2nd substate depends on the position of the parent state and it can be dragged partly out of its QGraphicsView.
The substates are added with the exact same piece of code.
I made a short video to demonstrate the behavior:
https://www.youtube.com/watch?v=obWVBnKueJc
I am using qt 4.8.

Is it a general problem to have a QGraphicsView inside a QGraphicsView?
Does anybody have a clue why this happens for the second, third etc widget?

Thanks in advance
veio

veiovis
27th July 2014, 15:00
I found out, when the 2nd substate's display is buggy:
https://www.youtube.com/watch?v=O_GjgVHEfrw

As long as the first substates's QGraphicsProxyWidget content is visible, the 2nd substates's QGraphicsProxyWidget is not displayed correctly,

anda_skoa
27th July 2014, 16:07
That sounds like a very complicated setup.
It is probably better to do the complete state chart inside on graphics scene, i.e. just let a state item be the parent of its sub state items and so on.

Cheers,
_

veiovis
27th July 2014, 21:20
Yeah, that would be a possible alternative.
But with multiple Qgraphicsviews the management of the substates would be way easier. For example scaling the graphicsview to view all substates of a states at once is one command.
With one big graphicsscene I would need to do that by hand.

d_stranz
29th July 2014, 03:56
With one big graphicsscene I would need to do that by hand.

Not necessarily. If you make custom QGraphicsObject class instances to represent each substate (i.e. containing all of the items that are now in the separate scenes used in your multiple views), then you simply set the scaling transformation for the substate graphics object you want to expand. One command, because the object will apply the same scaling to all of its children. These substate objects don't have to have any graphical representation, they can just serve as containers for the child object that do get displayed.

wysota
29th July 2014, 14:34
But with multiple Qgraphicsviews the management of the substates would be way easier. For example scaling the graphicsview to view all substates of a states at once is one command.
With one big graphicsscene I would need to do that by hand.

It is always one command, the difference is what the subject of that command is.

QGraphicsItem::childrenBoundingRect() returns a rectangle that encompasses all its children. You can use that to calculate the scale you need to apply to an item that contains the substate items to make all its children cover a particular area.