开发者

drawing a "preview" of line in simple graphical editor

Drawing line with QPainter. onMousePressed : saving (x0,y0) onMouseReleased : QPainter.drawLine (x0,y0,x1,y1)

I want to see preview of line on开发者_JS百科MouseMove. But if will redraw all picture it will be too long. How to do it?


Use a QGraphicsScene. Draw your background image as a QGraphicsPixmapItem and add the line preview as a QGraphicsLineItem. When the line is accepted, then remove the line item and draw it permanently on the pixmap. You can set the graphics scene to use OpenGL acceleration, http://doc.qt.nokia.com/qq/qq26-openglcanvas.html


I'd go simple for a first shot.

If your are not using any hardware accelerated rendering you can render in a QPixmap that you save as a member of your instance (lets call it buffer).

QPixmap* buffer = new QPixmap( this->size());
QPainter painter( buffer);
painter.draw(...) //draw your stuff in it

Then on paint when you track mouse moves render your buffer as a background (should be very fast since no transformation/blending is involved) then on top draw your dynamic line.

QPainter painter( this);
painter.drawPixmap( rect(), *buffer, rect());
painter.drawLine(...)

You must keep track of the dirtiness of your paint area to re-render buffer when needed (resize/stuff added/...).

NOTE: if your are using OpenGL same thing can be done with render buffer or pixel buffers ... see Qt PixelBuffer example

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜