1
votes

Using QGraphicsView/QGraphicsScene/QGraphicsItem, I need to create multiple views of another QGraphicsItem.

In other words, within QGraphicsScene I need to create multiple QGraphicItems which display portions of some other QGraphicsItem which is stored somewhere offscreen. It is kind like model/view framework, where one QGraphicsItem acts like a model, and other QGraphicsItems act like views - displaying (clipped) portions of that other item. (see attached picture) picture

How can I do that? Please note that "views" should not be read-only. Each view should react to mouse movements, keyboard input and should redraw itself properly when some items within the model change.

The dumbest way to do it would be to draw hidden item onto QImage and then display portions of that QImage within other items. HOwever, that would mean a lot of wasted memory. Is there any other way to do it?

Qt 4.8, VC2008 express, Windows platform.

--EDIT--

I need to display portions of the scene (or offscreen QGraphicsItem) within the scene. It is kinda like portals in 3d games.

1
Why is your "model" a QGraphicsItem? I would design it in a way where the "model" is a plain C++ (probably a Qt-)-object which provides the necessary data, so that each "view" QGraphicsItem can fetch the relevant data and paint it accordinglyAndreas Fester
@Andreas: Because I need to display portions of same QGraphicsItem several times.SigTerm
Ok, so paint() of your "model" item already paints everything as necessary, and you just want to show a specific area from the paint result in your "view" items, right?Andreas Fester
Did you try to simply call the paint() method of the model items from your view item's paint() method, and set a proper translation transformation before (and probably set the ItemClipsToShape flag on the view items)?Andreas Fester
@Andres: Yes, but it must react to mouse movements, handle focus/selection and views must redraw themselves correctly if underlying model changes. That's the problem.SigTerm

1 Answers

0
votes

After some research, I found out that (as far as I can tell) Qt has no (documented) methods for this kind of scenario.

So I've decided to write couple of my own methods that will

  1. Draw QGraphicsItems hierarchies to any QPaintDevice (traverse child hierarchies + call paint() methods for all items involved)
  2. Translate input (mouse/keyboard) events from any region to selected QGraphicsItem.

This might actually be a bit tricky because I'll need to handle clipping (items that clip children by their shape) and redraw of complex components like QGraphicsWidget, but as far as I can tell it can be done. Also, by doing this I'll lose BSP optimizations QGraphicsView provides, but for my particular scenario that should be an acceptable tradeoff.