#include "widget.h"
#include "ui_widget.h"
#include<QPainter>
#include<QTimer>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//点击移动按钮 移动图片
QTimer *timer= new QTimer(this);
timer->start(20);
connect(ui->btn,&QPushButton::clicked,[=](){
connect(timer,&QTimer::timeout,[=](){
posX+=20;
update();
});
});
}
void Widget::paintEvent(QPaintEvent *event)
{
/利用画家画图片
QPainter painter(this);
if(posX>this->width())
{
posX=0;
}
painter.drawPixmap(posX,100,QPixmap(":/Image/Luffy.png"));
}
Widget::~Widget()
{
delete ui;
}
Qt 简单的定时器和QPainter
最新推荐文章于 2024-11-15 22:11:31 发布