简体   繁体   中英

Qt4: “subview” using QGraphicsView

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) 图片

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM