对于QGraphicsScene,在QGraphicsItem上使用setZValue会导致主要的减速(For QGraphicsScene using setZValue on a QGraphic

编程入门 行业动态 更新时间:2024-10-23 10:23:30
对于QGraphicsScene,在QGraphicsItem上使用setZValue会导致主要的减速(For QGraphicsScene using setZValue on a QGraphicsItem causes major slowdown)

我正在使用Qt(Mac,版本4.7)使用QGraphicsView和QGraphicsScene渲染相当大的场景(来自Open Street Maps的地图数据)。 一切都很好,直到我尝试为场景中的项目设置Z值。 我尝试过两种不同的方法来做到这一点。 在一个,我只是做:

QGraphicsPathItem *item = scene->addPath(path, pen); item->setZValue(z);

另一个我创建自己的QGraphicsItem子类,但得到完全相同的问题。

减速的原因似乎在Qt方面。 设置z值后,场景需要很长时间才能生成(在任何显示之前需要几分钟,我得到旋转的死亡球),但一旦生成,速度就会恢复正常。 此外,当我尝试关闭应用程序时,它会在关闭之前挂起几分钟。 如果我单独留下z值,我没有看到任何这些问题,并且我添加了调试代码以验证它没有出现在我自己的代码中。

不幸的是,我需要设置z值才能正确渲染街道(例如道路周围的轮廓,使高速公路比街道更高的顺序等)。

任何帮助是极大的赞赏!

I'm using Qt (Mac, version 4.7) to rendering a rather large scene (map data from Open Street Maps) with QGraphicsView and QGraphicsScene. Everything works great until I try to set the Z value for the items in the scene. I've tried two separate approaches to do this. In one, I just do:

QGraphicsPathItem *item = scene->addPath(path, pen); item->setZValue(z);

and the other I create my own QGraphicsItem subclass, but get the exact same problem.

The cause of the slow down appears to be on the Qt side of things. It takes a very long time for the scene to generate once I set the z-value (it takes a few minutes before anything displays, and I get the spinning beach ball of death), but once it's generated, the speed is back to normal. Additionally, when I try to close the application it hangs for a few minutes before closing. I don't see any of these issues if I leave the z-value alone, and I've added debugging code to verify it's not occurring in my own code.

Unfortunately, I need to set the z-value in order to render streets correctly (e.g. outlines around roads, make highways a higher order than through streets, etc.).

Any help is greatly appreciated!

最满意答案

您可以尝试将bspTreeDepth设置为固定值。 它控制场景中项目的位置。 用大量现有物品改变深度可能非常昂贵。

另一个优化的候选者是itemIndexMethod 。 将其设置为noIndex实际上可能会提高性能。

You may try setting bspTreeDepth to a fixed value. It controls how an item in the scene is located. Changing the depth with a large number of existing items can be very costly.

Another candidate for optimization is itemIndexMethod. Setting it to noIndex may actually increase the performance.

更多推荐

本文发布于:2023-08-01 17:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:QGraphicsItem   QGraphicsScene   setZValue   slowdown   major

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!