Qt之窗口动画(下坠、抖动、透明度)

来源:互联网 发布:阿里云广州分公司 编辑:程序博客网 时间:2024/04/29 06:38

1.效果


2.下坠效果

通过计算桌面的宽度、高度,来设置动画的起始值和结束值。

void MainWindow::onDropWindow(){    QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "geometry");    QDesktopWidget *pDesktopWidget = QApplication::desktop();    int x = (pDesktopWidget->availableGeometry().width() - width()) / 2;    int y = (pDesktopWidget->availableGeometry().height() - height()) / 2;    pAnimation->setDuration(1000);    pAnimation->setStartValue(QRect(x, 0, width(), height()));    pAnimation->setEndValue(QRect(x, y, width(), height()));    pAnimation->setEasingCurve(QEasingCurve::OutElastic);    pAnimation->start(QAbstractAnimation::DeleteWhenStopped);}
3.抖动效果

获取界面的坐标,然后进行上、下、左、右坐标浮动,通过setKeyValueAt()来设置每一时刻的位置,实现抖动效果。

void MainWindow::onShakeWindow(){    QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos");    pAnimation->setDuration(500);    pAnimation->setLoopCount(2);    pAnimation->setKeyValueAt(0, QPoint(geometry().x() - 3, geometry().y() - 3));    pAnimation->setKeyValueAt(0.1, QPoint(geometry().x() + 6, geometry().y() + 6));    pAnimation->setKeyValueAt(0.2, QPoint(geometry().x() - 6, geometry().y() + 6));    pAnimation->setKeyValueAt(0.3, QPoint(geometry().x() + 6, geometry().y() - 6));    pAnimation->setKeyValueAt(0.4, QPoint(geometry().x() - 6, geometry().y() - 6));    pAnimation->setKeyValueAt(0.5, QPoint(geometry().x() + 6, geometry().y() + 6));    pAnimation->setKeyValueAt(0.6, QPoint(geometry().x() - 6, geometry().y() + 6));    pAnimation->setKeyValueAt(0.7, QPoint(geometry().x() + 6, geometry().y() - 6));    pAnimation->setKeyValueAt(0.8, QPoint(geometry().x() - 6, geometry().y() - 6));    pAnimation->setKeyValueAt(0.9, QPoint(geometry().x() + 6, geometry().y() + 6));    pAnimation->setKeyValueAt(1, QPoint(geometry().x() - 3, geometry().y() - 3));    pAnimation->start(QAbstractAnimation::DeleteWhenStopped);}
4.透明度效果

设置每一时刻的透明度值,动画结束时界面还原(透明度再为1)

void MainWindow::onOpacityWindow(){    QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "windowOpacity");    pAnimation->setDuration(1000);    pAnimation->setKeyValueAt(0, 1);    pAnimation->setKeyValueAt(0.5, 0);    pAnimation->setKeyValueAt(1, 1);    pAnimation->start(QAbstractAnimation::DeleteWhenStopped);}


原文链接:http://blog.csdn.net/liang19890820/article/details/51888114



3 0
原创粉丝点击