当前位置: 动力学知识库 > 问答 > 编程问答 >

performance - For QGraphicsScene using setZValue on a QGraphicsItem causes major slowdown

问题描述:

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!

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: