Qt-Paint系统

来源:互联网 发布:浙江师范行知学院 编辑:程序博客网 时间:2024/06/05 05:47

Qt里面,要想画图,只有把画图的过程放入paintEvent()方法中,每次窗口变化时会回调paintEvent() 方法

Paint events are sent to widgets that need to update themselves, for
instance when part of a widget is exposed because a covering widget was
moved.

QPainter

The QPainter class performs low-level painting on widgets and other paint devices.

QPainter 类对象作用于继承QPaintDevice 类的对象

QPaintDevice

QPainter对象可以在QPaintDevice上进行绘画操作

常用的QPaintDevice 子类有QWidget, QPixmap, QImage

示例

//画图并保存为图片void SomeWidget::painterEvent(){    QImage image(50, 50, QImage::Format_RGB32);    QPainter painter;    painter.begin(&image);    //draw something    image.save("filename.jpg", "JPEG");}

QPaintEngine

The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a given platform.

QPaintEngine 不直接提供给开发人员使用,提供接口,供QPainter往不同的device上绘制图形。

Qt-Paint系统

参考链接

Qt的paint系统主要是基于QPainter, QPaintDevice & QPaintEngine

QPainter 用于画图操作

QPaintDevice 是一个二维的抽象空间,QPainter 可以在上面画图,QPaintEngine 为其提供了painter画图的相关接口

QPaintEngine 被用于QPainterQPaintDevice 内部,对外透明,除非程序员创建自己的device.

paint-system