qfedu-qt-level/qtdemo03/delayform2.cpp

37 lines
788 B
C++

#include "delayform2.h"
#include "ui_delayform2.h"
DelayForm2::DelayForm2(QWidget *parent) :
QWidget(parent),
ui(new Ui::DelayForm2)
{
ui->setupUi(this);
ui->lcdNumber->display(5);
timer = new QTimer(this);
ui->imageLabel->setScaledContents(true);
connect(timer,&QTimer::timeout,[&]{
int n = ui->lcdNumber->intValue();
if(n == 0){
timer->stop();
// ui->imageLabel->setPixmap(QPixmap(":/images/images/butterfly.png"));
return;
}
ui->lcdNumber->display(--n);
});
timer->start(1000);
// 延迟 10 秒
QTimer::singleShot(5000,[&]{
ui->imageLabel->setPixmap(QPixmap(":/images/images/butterfly.png"));
});
}
DelayForm2::~DelayForm2()
{
delete ui;
}