int main(int argc, char *argv[]) { // QApplication a(argc, argv); // MainWindow w; // w.show(); QApplication app(argc, argv); QLabel lbl1("Animated Window1"); QLabel lbl2("Animated Window2"); QPropertyAnimation* panim1 = new QPropertyAnimation(&lbl1, "geometry"); panim1->setDuration(3000); panim1->setStartValue(QRect(120, 0, 100, 100)); panim1->setEndValue(QRect(480, 380, 200, 200)); panim1->setEasingCurve(QEasingCurve::InElastic /*InOutExpo*/); QPropertyAnimation* panim2 = new QPropertyAnimation(&lbl2, "pos"); panim2->setDuration(3000); panim2->setStartValue(QPoint(240, 0)); panim2->setEndValue(QPoint(240, 480)); panim2->setEasingCurve(QEasingCurve::OutElastic /*OutBounce*/); QParallelAnimationGroup group; group.addAnimation(panim1); group.addAnimation(panim2); group.setLoopCount(3); group.start(); lbl1.show(); lbl2.show(); return app.exec(); return app.exec(); }
//! [10] Robot::Robot(QGraphicsItem *parent) : RobotPart(parent) { setFlag(ItemHasNoContents); QGraphicsObject *torsoItem = new RobotTorso(this); QGraphicsObject *headItem = new RobotHead(torsoItem); QGraphicsObject *upperLeftArmItem = new RobotLimb(torsoItem); QGraphicsObject *lowerLeftArmItem = new RobotLimb(upperLeftArmItem); QGraphicsObject *upperRightArmItem = new RobotLimb(torsoItem); QGraphicsObject *lowerRightArmItem = new RobotLimb(upperRightArmItem); QGraphicsObject *upperRightLegItem = new RobotLimb(torsoItem); QGraphicsObject *lowerRightLegItem = new RobotLimb(upperRightLegItem); QGraphicsObject *upperLeftLegItem = new RobotLimb(torsoItem); QGraphicsObject *lowerLeftLegItem = new RobotLimb(upperLeftLegItem); //! [10] //! [11] headItem->setPos(0, -18); upperLeftArmItem->setPos(-15, -10); lowerLeftArmItem->setPos(30, 0); upperRightArmItem->setPos(15, -10); lowerRightArmItem->setPos(30, 0); upperRightLegItem->setPos(10, 32); lowerRightLegItem->setPos(30, 0); upperLeftLegItem->setPos(-10, 32); lowerLeftLegItem->setPos(30, 0); //! [11] //! [12] QParallelAnimationGroup *animation = new QParallelAnimationGroup(this); QPropertyAnimation *headAnimation = new QPropertyAnimation(headItem, "rotation"); headAnimation->setStartValue(20); headAnimation->setEndValue(-20); QPropertyAnimation *headScaleAnimation = new QPropertyAnimation(headItem, "scale"); headScaleAnimation->setEndValue(1.1); animation->addAnimation(headAnimation); animation->addAnimation(headScaleAnimation); //! [12] QPropertyAnimation *upperLeftArmAnimation = new QPropertyAnimation(upperLeftArmItem, "rotation"); upperLeftArmAnimation->setStartValue(190); upperLeftArmAnimation->setEndValue(180); animation->addAnimation(upperLeftArmAnimation); QPropertyAnimation *lowerLeftArmAnimation = new QPropertyAnimation(lowerLeftArmItem, "rotation"); lowerLeftArmAnimation->setStartValue(50); lowerLeftArmAnimation->setEndValue(10); animation->addAnimation(lowerLeftArmAnimation); QPropertyAnimation *upperRightArmAnimation = new QPropertyAnimation(upperRightArmItem, "rotation"); upperRightArmAnimation->setStartValue(300); upperRightArmAnimation->setEndValue(310); animation->addAnimation(upperRightArmAnimation); QPropertyAnimation *lowerRightArmAnimation = new QPropertyAnimation(lowerRightArmItem, "rotation"); lowerRightArmAnimation->setStartValue(0); lowerRightArmAnimation->setEndValue(-70); animation->addAnimation(lowerRightArmAnimation); QPropertyAnimation *upperLeftLegAnimation = new QPropertyAnimation(upperLeftLegItem, "rotation"); upperLeftLegAnimation->setStartValue(150); upperLeftLegAnimation->setEndValue(80); animation->addAnimation(upperLeftLegAnimation); QPropertyAnimation *lowerLeftLegAnimation = new QPropertyAnimation(lowerLeftLegItem, "rotation"); lowerLeftLegAnimation->setStartValue(70); lowerLeftLegAnimation->setEndValue(10); animation->addAnimation(lowerLeftLegAnimation); QPropertyAnimation *upperRightLegAnimation = new QPropertyAnimation(upperRightLegItem, "rotation"); upperRightLegAnimation->setStartValue(40); upperRightLegAnimation->setEndValue(120); animation->addAnimation(upperRightLegAnimation); QPropertyAnimation *lowerRightLegAnimation = new QPropertyAnimation(lowerRightLegItem, "rotation"); lowerRightLegAnimation->setStartValue(10); lowerRightLegAnimation->setEndValue(50); animation->addAnimation(lowerRightLegAnimation); QPropertyAnimation *torsoAnimation = new QPropertyAnimation(torsoItem, "rotation"); torsoAnimation->setStartValue(5); torsoAnimation->setEndValue(-20); animation->addAnimation(torsoAnimation); //! [13] for (int i = 0; i < animation->animationCount(); ++i) { QPropertyAnimation *anim = qobject_cast<QPropertyAnimation *>(animation->animationAt(i)); anim->setEasingCurve(QEasingCurve::SineCurve); anim->setDuration(2000); } animation->setLoopCount(-1); animation->start(); //! [13] }