简体   繁体   English

Qt4:使用QGraphicsView的“子视图”

[英]Qt4: “subview” using QGraphicsView

Using QGraphicsView/QGraphicsScene/QGraphicsItem, I need to create multiple views of another QGraphicsItem. 使用QGraphicsView / QGraphicsScene / QGraphicsItem,我需要创建另一个QGraphicsItem的多个视图。

In other words, within QGraphicsScene I need to create multiple QGraphicItems which display portions of some other QGraphicsItem which is stored somewhere offscreen. 换句话说,在QGraphicsScene中,我需要创建多个QGraphicItems,这些QGraphicItems显示存储在屏幕外某个地方的其他QGraphicsItem的一部分。 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. 这有点像模型/视图框架,其中一个QGraphicsItem的行为类似于模型,而其他QGraphicsItems的行为类似于视图-显示(剪切)另一项的一部分。 (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. 最愚蠢的方法是将隐藏的项目绘制到QImage上,然后在其他项目中显示该QImage的部分。 HOwever, that would mean a lot of wasted memory. 但是,这将浪费大量内存。 Is there any other way to do it? 还有其他方法吗?

Qt 4.8, VC2008 express, Windows platform. Qt 4.8,VC2008 Express,Windows平台。

--EDIT-- - 编辑 -

I need to display portions of the scene (or offscreen QGraphicsItem) within the scene. 我需要显示场景的场景(或屏幕外的QGraphicsItem)的部分。 It is kinda like portals in 3d games. 这有点像3D游戏中的门户。

After some research, I found out that (as far as I can tell) Qt has no (documented) methods for this kind of scenario. 经过研究,我发现(据我所知)Qt尚无(已记录)这种情况的方法。

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) 将QGraphicsItems层次结构绘制到任何QPaintDevice(遍历子层次结构+对涉及的所有项目调用paint()方法)
  2. Translate input (mouse/keyboard) events from any region to selected QGraphicsItem. 将来自任何区域的输入(鼠标/键盘)事件转换为选定的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. 这实际上可能有点棘手,因为我需要处理裁剪(按形状裁剪子项的项目)并重画QGraphicsWidget之类的复杂组件,但据我所知可以完成。 Also, by doing this I'll lose BSP optimizations QGraphicsView provides, but for my particular scenario that should be an acceptable tradeoff. 同样,这样做,我将失去QGraphicsView提供的BSP优化,但是对于我的特殊情况,这应该是可以接受的折衷方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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