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);

 

转载于:https://www.cnblogs.com/godfaber/p/9036648.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值