Qt中的QGraphicsScene等对象的坐标系是怎么设置的

Qt中的QGraphicsScene等对象的坐标系是怎么设置的,第1张

可以使用setSceneRect()设置QGraphicsScene的大小。如果不设置,则默认为scene中包含所有子元素的边界区域( itemsBoundingRect()函数的返回值)。

更详细的说明参看QGraphicsScene的文档,讲解很详细,看下面这段:

The scene's bounding rect is set by calling setSceneRect(). Items can be placed at any position on the scene, and the size of the scene is by default unlimited. The scene rect is used only for internal bookkeeping, maintaining the scene's item index. If the scene rect is unset, QGraphicsScene will use the bounding area of all items, as returned by itemsBoundingRect(), as the scene rect. However, itemsBoundingRect() is a relatively time consuming function, as it operates by collecting positional information for every item on the scene. Because of this, you should always set the scene rect when operating on large scenes.

参考 QGraphicsItemGroup

QGraphicsItemGroup 类提供了一个容器,该容器将一组项目视为单个项目。

QGraphicsItemGroup 是一种特殊类型的复合项,它会将自身及其所有子项视为一个项(即,所有子项的所有事件和几何都合并在一起)。当用户希望将几个较小的 item 分组为一个大 item 时,通常在演示工具中使用 item 组,以简化 item 的移动和复制。

如果只想将 item 存储在其他项目中,则可以通过将合适的父级传递给 setParentItem() 来直接使用任何 QGraphicsItem 。

QGraphicsItemGroup 的 boundingRect() 函数返回项目组中所有项目的边界矩形。 QGraphicsItemGroup 忽略其子项上的 ItemIgnoresTransformations 标志(即,相对于组项的几何形状,将子项视为可变形的)。

有两种构造项目组的方法。最简单,最常见的方法是将项目列表(例如所有选定的项目)传递给 createItemGroup() ,该列表将返回新的 QGraphicsItemGroup 项目。另一种方法是手动构造 QGraphicsItemGroup 项,然后调用 addItem() 将其添加到场景中,然后通过调用 addToGroup() 一次将项手动添加到组中。要拆除(“取消分组”) item 组,可以调用 destroyItemGroup() ,也可以通过调用 removeFromGroup() 手动从组中删除所有 item。

与调用 setParentItem() (仅保留子项的父项相对位置和转换)相反,添加和删除项的 *** 作将保留项的场景相对位置和转换。

addtoGroup() 函数可将目标项目重新添加到该项目组,从而使项目相对于场景的位置和变换保持完整。从视觉上看,这意味着通过 addToGroup() 添加的项目将由于此 *** 作而保持完全不变,而不管该项目或组的当前位置或转换如何;尽管该 item 的位置和 rect 可能会发生变化。

removeFromGroup() 函数的语义与 setParentItem() 相似,它将项目作为项目组的父项目。与 addToGroup() 一样,项目的场景相对位置和变换保持不变。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/7832664.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存