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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM