PDA

View Full Version : How to accelerate the running speed of the qt program?



superwave
19th June 2011, 17:18
First:


QGraphicsItem *pnode = new QGraphicsItem[6376]

scene = new QGraphicsScene(0, 0, Xmax*VisZoom, Ymax*VisZoom);

Then
add the 6376 items on the scene using:

scene->addItem(&pnode)
As shown below: each red spot represents an item
http://www.qtcentre.org/attachment.php?attachmentid=6585&d=1308491266

However, it becomes very slow if I want to change the size of the 6376 items simultaneously using: piNode[i].setScale. It will take about 30 seconds.

Moreover, even I use: void QGraphicsView::scale ( qreal sx, qreal sy ) to resize the whole scene, it still cost lots of time.

What's the problem? Can I speed up the program? Thanks a lot.

mvuori
19th June 2011, 17:37
I don't know, but I'd try and see what happens when making a copy of the nodes and change scale of the items "offline" piNodeCopy[i].setScale and then replacing the node set in the scene.

superwave
19th June 2011, 18:56
I don't know, but I'd try and see what happens when making a copy of the nodes and change scale of the items "offline" piNodeCopy[i].setScale and then replacing the node set in the scene.

This is the same, just like replace the items on the scene.

Actually, it will also take about 30 minutes to show the items on the scene for the first time.

SixDegrees
19th June 2011, 23:41
There are several flags that can be used to optimize graphicsView/Scene; I don't have access to the docs at the moment, but they're worth playing with. If you don't need to do things like collision detection, for instance, you can turn it off and save a good deal of computation.There's a decent discussion here (http://thesmithfam.org/blog/2007/02/03/qt-improving-qgraphicsview-performance/) of various techniques; read through the comments as well.

wysota
20th June 2011, 00:31
First thing to do is to enable caching for your items. Next thing to do is to put your items into groups and apply an empty QGraphicsEffect on the group. This won't speed up scaling but it will speed up other operations. Next, simplify drawing of items using level-of-detail information. If that's not enough, we'll suggest other things. And avoid using setScale() on items separately, I don't know what you're trying to do but most likely if you are scaling all items then what you really want is to scale the whole scene by calling QGraphicsView::scale().

Also consider using an OpenGL viewport or switching the view to FullViewportUpdate mode.

superwave
20th June 2011, 06:03
There are several flags that can be used to optimize graphicsView/Scene; I don't have access to the docs at the moment, but they're worth playing with. If you don't need to do things like collision detection, for instance, you can turn it off and save a good deal of computation.There's a decent discussion here (http://thesmithfam.org/blog/2007/02/03/qt-improving-qgraphicsview-performance/) of various techniques; read through the comments as well.

Thank you so much for your help.


First thing to do is to enable caching for your items. Next thing to do is to put your items into groups and apply an empty QGraphicsEffect on the group. This won't speed up scaling but it will speed up other operations. Next, simplify drawing of items using level-of-detail information. If that's not enough, we'll suggest other things. And avoid using setScale() on items separately, I don't know what you're trying to do but most likely if you are scaling all items then what you really want is to scale the whole scene by calling QGraphicsView::scale().

Also consider using an OpenGL viewport or switching the view to FullViewportUpdate mode.

Thank you very much for your advice. I will try right now.