Qt之窗口动画(下坠、抖动、透明度)(还有好多相关帖子)
2016-07-18 21:22
513 查看
简述
前面几节中我们介绍了关于动画的基本使用,有属性动画、串行动画组、并行动画组。这节我们来实现一些特效,让交互更顺畅。简述
示例
效果
源码
更多参考
示例
下面,我们以geometry、pos、windowOpacity属性为例,来实现窗体的下坠、抖动、透明度效果。效果
源码
下坠效果:通过计算桌面的宽度、高度,来设置动画的起始值和结束值。
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); }
抖动效果:
获取界面的坐标,然后进行上、下、左、右坐标浮动,通过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); }
透明度效果:
设置每一时刻的透明度值,动画结束时界面还原(透明度再为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); }
是不是很有趣,还不快点儿,实现属于自己的动画。
更多参考
Qt之动画框架Qt之QPropertyAnimation
Qt之QSequentialAnimationGroup
Qt之QParallelAnimationGroup
Qt之QPauseAnimation
http://blog.csdn.net/liang19890820/article/details/51888114
相关文章推荐
- Qt之Windows资源文件(.rc文件)
- Qt学习(四)—实例涂鸦画板mspaint
- QT第一天学习
- qt5集成libcurl实现tftp和ftp的方法之三:搭建FTP时,当ftpServer端默认登录的目录不是根目录/时,有一个bug会产生的解决办法
- Qt之图标切分与合并(关键是使用QPixmap的copy函数来拷贝整张图片的某个区域)
- qt day1
- Qt-crateor 编译 ROS
- 简单的QT绘图程序(把全部的点都记录下来,然后在paintEvent里使用drawLine函数进行绘制,貌似效率很低。。。)
- VS_QT中配置qDebug输出
- VS2008下搭建QT环境
- QT5程序打包发布
- QT各种乱码解决方案
- 从无到有,从动态链编到静态链编,与清华大学合作完成了一个Qt项目
- QT中QtConcurrent创建并行线程的方法
- Qt::WindowFlags枚举类型解析
- QTreeWidget树形控件设计
- Qt产生随机数
- windows10 qt5 mingw32编译cryptopp563
- Qt5.6windows打包发布
- IOT_MQTT_CoAP_XMPP