Qt绘图设备QPicture

#include "widget.h"
#include "ui_widget.h"
#include <QPicture>
#include <QPainter>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    /* 绘图设备 可以记录和重现绘图指令 */
    QPicture picture;
    QPainter painter;
    painter.begin(&picture);
    painter.setPen(Qt::red);
    painter.drawEllipse(QPoint(100, 100), 50, 50);
    painter.end();
    picture.save("D:\\picture.fr");
}

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    /* 重现picture */
    QPicture picture;
    picture.load("D:\\picture.fr");
    painter.drawPicture(0, 0, picture);
}

posted @ 2022-08-05 15:08  thomas_blog  阅读(57)  评论(0编辑  收藏  举报