本文实例为大家分享了Qt实现樱花飞舞效果的具体代码,供大家参考,具体内容如下
应女友要求,使用Qt做了一个在电脑桌面樱花飞舞的小程序。这里面用到了Qt动画效果QPropertyAnimation类来控制飞舞效果。使用label加载樱花图案。大概的核心代码如下:
Widget::Widget(QWidget *parent) :
QWidget(parent),
timer(new QTimer(this)),
pixmap(new QPixmap(":/cherry.png")),
ui(new Ui::Widget)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint | windowFlags()); //去除窗体标题
this->resize(qApp->desktop()->availableGeometry().size());
this->setAttribute(Qt::WA_TranslucentBackground, true); //设置背景透明
this->setAutoFillBackground(true);
this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); //窗口总在最顶层
connect(timer,SIGNAL(timeout()),this,SLOT(start()));
QPixmap *pixmap = new QPixmap(":/cherry.png");
pixmap->scaled(ui->label->size(), Qt::KeepA