Qt手动调用绘图事件

#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

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

    posX = 0;

    connect(ui->pushButton, &QPushButton::clicked, this, [=](){
        qDebug() << "clickedSlot";
        posX += 10;
        update();
    });
}

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(posX, 0, QPixmap(":/girl.jpg"));
}


点击“移动”

posted @ 2022-08-04 17:26  thomas_blog  阅读(122)  评论(0编辑  收藏  举报