PDA

View Full Version : how to draw a long curve quickly?



weixj2003ld
22nd August 2011, 02:48
I want to draw a curve in QGraphicsScene and it is composed by about 100,000 points. how to draw it quickly?
I want to draw part of it at first,when user drag mouse,I draw another part according the mouse moves,but i do not know how to realize it?
do you have the other method?

wysota
22nd August 2011, 06:51
QPainterPath and QGraphicsPathItem

weixj2003ld
22nd August 2011, 07:59
Thk u for your answer.
I know that use QPainterPath and QGraphicsPathItem to
create a curve.
My question is that when the points number is vevy large ,for example,100,000,how to draw it quickly?

wysota
22nd August 2011, 09:37
You don't. If the number of points is large then it takes longer to draw them than when there is fewer of them. Optimize your point count and cache whatever you can.

weixj2003ld
23rd August 2011, 09:59
”cache whatever you can“,sorry,I do not know what it means.

wysota
23rd August 2011, 16:03
Keep intermediate values in memory instead of recalculating them each and every time when you need to use them.

weixj2003ld
24th August 2011, 02:25
I want to draw a curve in QGraphicsScene and it is composed by about 100,000 points. when I draw it all at
first,it will cost a long time.
I think if I should draw apart of it,and draw other part according user's draging the scroll bar.

wysota
24th August 2011, 08:32
Yes, you can segment your path and draw only those segments that are visible. You can also render your whole path to a pixmap and then just render the pixmap instead of stroking the path in each frame (especially if your path is static).