Qt 画布(基于QImage 以及 QPainterPath)

来源:互联网 发布:国产网络腐剧 编辑:程序博客网 时间:2024/06/05 02:31

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

这里写图片描述

原创粉丝点击