PDA

View Full Version : Optimizing the painting on a custom QGraphicsItem



eternalthinker
22nd October 2012, 05:57
I have a custom QGraphicsItem which has a QPainterPath as member.
As the mouse is dragged, the movement is traced onto this path. The paint() method in the QGrahicsItem draws the whole path everytime a new point is added to the path.

The purpose of implementing this is, the whole path is drawn to an image when the mouse is released (The image needs to be free for other drawing as long as possible, so can't directly draw on it).

The issue here is, as the path gets longer, the updating of graphics on QGraphicsScene gets visibly slower (while mouse is dragged for a long time).

Is there a way to optimize and speed up the paint() method in this case, while keeping the path info which needs to be directly drawn to an image?

wysota
22nd October 2012, 10:34
You can draw to a temporary pixmap and only update the pixmap with the last created segment of the path. Then when the user releases the mouse, either draw the pixmap to the destination image or restroke the path directly.