Qt:QSequentialAnimationGroup 秒速五厘米 2022-10-24 11:44 7阅读 0赞 #include "widget.h" #include <QPushButton> #include <QPropertyAnimation> #include <QDebug> Widget::Widget(QWidget *parent) : QWidget(parent) { this->resize(300, 200); QPushButton *btn1 = new QPushButton("first", this); btn1->setGeometry(10, 10, 100, 30); QPushButton *btn2 = new QPushButton("second", this); btn2->setGeometry(10, 45, 100, 30); QPropertyAnimation *anim1 = new QPropertyAnimation(btn1, "geometry"); anim1->setDuration(2000); anim1->setStartValue(QRectF(10, 10, 100, 30)); anim1->setEndValue(QRectF(200, 150, 100, 30)); QPropertyAnimation *anim2 = new QPropertyAnimation(btn2, "geometry"); anim2->setDuration(2000); anim2->setStartValue(QRect(10, 45, 100, 30)); anim2->setEndValue(QRect(200, 195, 100, 30)); // sGroup = new QSequentialAnimationGroup; // Sequential Group // sGroup->addAnimation(anim1); // sGroup->addAnimation(anim2); pGroup = new QParallelAnimationGroup; // Parallel Group pGroup->addAnimation(anim1); pGroup->addAnimation(anim2); connect(btn1, SIGNAL(clicked()), this, SLOT(btn_clicked())); connect(btn2, SIGNAL(clicked()), this, SLOT(btn_clicked())); } void Widget::btn_clicked() { // sGroup->start(QPropertyAnimation::DeleteWhenStopped); //如果动画完成自动清理内存 //因此移动一次之后就算再次点击按钮也不会移动了 pGroup->start(QPropertyAnimation::DeleteWhenStopped); } ![c9da6d9ff7c89a9f2527a6675bbab79653f.jpg][] ![b84fa883d10e00e73b29079adcc498bcef5.jpg][] 任意一个按钮点击都都会移动按钮,先移动按钮1,再移动按钮2 ![a06844a8197e03ffdaaf1a90ddbddd33.png][] ![ee771c7e079bc4054f52441c011c59868fc.jpg][] ![c580a0029b629c0c8e3546fe307648a3809.jpg][] 任意一个按钮点击都都会移动按钮:按钮1&按钮2并行移动 ![a083459f852f42b1d935e2afc9e121e5.png][] 串行顺序运行动画对象 [c9da6d9ff7c89a9f2527a6675bbab79653f.jpg]: /images/20221024/998840f40e9e49b3b99ac87ad7476e66.png [b84fa883d10e00e73b29079adcc498bcef5.jpg]: /images/20221024/83383249383147e596c149f1fa7cb448.png [a06844a8197e03ffdaaf1a90ddbddd33.png]: /images/20221024/fe9d30b8fe084597ab853ec9d0e4e63d.png [ee771c7e079bc4054f52441c011c59868fc.jpg]: /images/20221024/d7bd0d92fa4f46e698697297382a8b86.png [c580a0029b629c0c8e3546fe307648a3809.jpg]: /images/20221024/80733c2119654a69a5ba08ea01ca36cb.png [a083459f852f42b1d935e2afc9e121e5.png]: /images/20221024/47fb26da7e564c308978a999aad1b8d7.png
还没有评论,来说两句吧...