对于 QGraphicsScene 在 QGraphicsItem 上使用 setZValue 会导致速度大幅下降
我正在使用 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试将
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.