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"));
}
点击“移动”