您的位置:首页 > 编程语言 > Qt开发

Qt 画布(基于QImage 以及 QPainterPath)

2017-07-31 14:12 239 查看

Qt 画布(基于QImage 以及 QPainterPath)

QPainterPath:实时记录描绘的轨迹

QImage:画布

具体实现:

paintEvent:负责重绘画布,及时更新。

QMouseEvent:鼠标事件,负责动态的将鼠标位置信息记录到QPainterPath中。

paint:在画布上绘制QPainterPath的每一个图形。

基本流程:

鼠标左键点击(1) –> clear the previous path_points and new path(QPainterPath).

鼠标左键点击(2) –> set start_point and append it into path_points.

鼠标移动事件(1) –> add point into path_points and paint painterPath.

鼠标左键释放(1) –> add point into path_points and paint painterPath.

鼠标双击事件(1) –> reset current image back to bg_image

鼠标右键点击(1) –> save the image with “a.png”

重绘事件 –> redraw the image.

效果图:

注:QImage为底层青草色画布,黑色笔记是绘制在该画布上的QPainterPath

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: