For QGraphicsScene using setZValue on a QGraphicsItem causes major slowdown

旧时模样 提交于 2019-12-11 05:21:56

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/8347849/for-qgraphicsscene-using-setzvalue-on-a-qgraphicsitem-causes-major-slowdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!