QPropertyAnimation实现图形,控件的旋转和位移动画,尤其是旋转
QPropertyAnimation可以简单方便的实现对象的旋转和移动的动画效果。
1. 移动
Pixmap *item = new Pixmap(kineticPix);
QPropertyAnimation *animation = new QPropertyAnimation(item, "pos");
anim1->setStartValue(QPoint(-100, -100));
anim1->setEndValue(QPoint(500, 100));
anim1->setEasingCurve(QEasingCurve::Linear);
connect(anim1, SIGNAL(finished()), this, SLOT(EndAnimation())); //动画结束后需要执行的函数
anim1->start(QAbstractAnimation::KeepWhenStopped);
2. 旋转
想要实现旋转的动画效果,要旋转的对象就必须支持‘’rotation‘’属性,否则无法实现旋转动画。需要在类中定义:
Q_PROPERTY(QPointF pos READ pos WRITE setPos) //移动
Q_PROPERTY(int rotation READ rotation WRITE setRotation) //旋转
然后同理处理旋转:
QPropertyAnimation *animation = new QPropertyAnimation(item, "rotation");
animation->setDuration(2000);
animation->setStartValue(0);
animation->setEndValue(90);
animation->setLoopCount(1); //旋转次数
connect(animation, SIGNAL(finished()), this, SLOT(onAnimation()));
animation->start(QAbstractAnimation::KeepWhenStopped);
最新文章
- (十)Maven依赖详解
- ca 自签名证书 并实现HAProxy https功能
- 想学习Android开发
- centos7 firewall 防火墙 命令
- 在你决定从事iOS开发前需要清楚的几个问题
- 【原】升级nginx注意点
- 1187: [HNOI2007]神奇游乐园 - BZOJ
- 【C语言】- 数据输出-printf( )和putchar( )
- Python 的格式化字符串format函数
- 支付宝openssl漏洞肆虐 互联网巨头称目前已修复
- javascript——处理(获取)浏览器版本、操作系统
- BZOJ 1024 生日快乐
- Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse
- 用程序对hdfs进行操作。
- uva 11181 - Probability|Given
- 解决 bootstrap 在IE8下的兼容问题
- 高性能网站架构设计之缓存篇(1)- Redis C#客户端
- 对deep learning的第一周调研
- 【网络流】POJ1273 Drainage Ditches
- Javascript 精简语法介绍