1

So, if I figure out this correctly, QGraphicsItem are (abstract) graphics items which belong to one QGraphicsScene (which is scene manager basically).

QGraphicsView is specific "view" into that scene and multiple views can view same scene.

If I were to have 3 views viewing on same scene, where one view views 1-5/10 items, other 5-10/10 and third view views all of them, I would need to have one scene and three views with some kind of filters which items to draw. Is this possible ?

How can I filter which QGraphicsItems are displayed in specific QGraphicsView?

edin-m
  • 3,021
  • 3
  • 17
  • 27

1 Answers1

2

It's not possible to do directly, but is rather easy with viewscenes (akin to viewmodels).

Item visibility is an integral part of the scene, not a view. This makes sense: once you start letting scenes change item properties, there's never a sane place where one might stop. Next you want to move items a bit, etc. So this simply isn't supported in the current design.

You can have a prototype scene that has all items, and then viewscenes (viewmodels) that have copies of the items you wish visible. The items are small and cheap to copy, so even with a thousand items in a scene, the cost to implement it that way is minuscule. Just make a factory to make copies of all item types you're interested in, and run them on the prototype scene, ignoring the items you wish not shown.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • What if I have some logic attached to graphics items, like animation, additional color controls? From where I am now controlling one item, I would need to apply that control on list of items which sounds to me more complicated than it should be. Is there really no better way ? – edin-m Aug 10 '15 at 20:22
  • @EdinM. There is no better way. Visibility is an item's property, and an item can be in one scene at any given time. You can easily set things up so that the viewscene items mirror the items in the root scene. Just use proxy items instead of item copies. It should be easy to set up a proxy item, heck, even a proxy scene that automatically creates proxy items as needed. It'd require a bit of ingenuity, but it's doable thanks to the `itemChange` method. – Kuba hasn't forgotten Monica Aug 10 '15 at 21:21