GraphicItem in multiple ViewBoxes

41 views
Skip to first unread message

Andre G

unread,
May 7, 2019, 3:28:04 AM5/7/19
to pyqtgraph
Hi all,

If anyone is interested, here is a corresponding SO question with a minimum working example. In general I want to achieve something like this:

Add three Items to a scene. Then I want a ViewBox to show the first Item, the second ViewBox to show the second Item. The third Item should be displayed in both ViewBoxes.

But as far as I know, this will be hard to do. Because either I have to intercept PaintEvents, to transform the third Item just before the Event is further propagated through the ViewBox. Will it might be possible, it seems like an bad idea to me, introducing a lot of imponderabilities like possible racing conditions between ViewBoxes.

How hard will it be to implement all the nice pyqtgraph functionality, like mouse panning, using Qt native Views and Scenes? 0Is there another approach to achieve what I am looking for?




Best,
Acha

Patrick

unread,
May 7, 2019, 10:32:48 PM5/7/19
to pyqtgraph
Hi,

If you are only going to be doing something relatively simple like this, then perhaps just making duplicates of the items and adding them to each ViewBox manually would be easiest. You can synchronise the pan/zoom of the ViewBoxes easily with existing axes linking methods. You would just need to manually update the data for the two plot items when it changes, or code in some signal/slot magic to do this automatically.

Sure, might seem inefficient, but if it get the job done...

Patrick

Andre G

unread,
May 8, 2019, 8:03:25 AM5/8/19
to pyqtgraph
Hi,

yes, it really is nothing to fancy. But I will add a significant amount (several thousands) of GraphicItems and they all are supposed to be synced to a central resource keeping all information about the items.

However, I found a solution to the problem: Instead of using ViewBoxes I straight using GraphicViews. The main functionally (synronizing the view range between individual views, panning, scaling) is either already implemented or (hopfully) easily to implement. The GraphicsItems can be added to a shared scene and I will use the drawBackground to paint the 'view local' items.

The standing question now is: Is there any drawback to this approach? Do I miss something when using GraphicsViews over ViewBoxes?


Best,
Acha

Luke Campagnola

unread,
May 11, 2019, 6:00:31 PM5/11/19
to pyqt...@googlegroups.com
The main reason for viewbox to exist is that there are many cases where we don't want the viewbox to cover the entire graphicsview -- for example, when making space for axes/labels, or when we have multiple view boxes per graphicsview. As you have found, one downside to this approach is that the nice shared-scene feature of graphicsview becomes useless.

I agree with Patrick that usually just duplicating items is the easiest way to go here, but in the rare cases where duplication is not an option, then using bare graphicsview is a reasonable solution.

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/03ffe149-02e0-41bc-9d27-e68223cbf69c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages