使用QParallelAnimationGroup实现QEasingCurve动作组group并行动作

使用QParallelAnimationGroup可以实现多个控件的并行动作。

使用以上的几个动作曲线来并行控制不同的动作。

代码如下:

void MainWindow::keyPressEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_M)
    {
        QPropertyAnimation *animation1 = new QPropertyAnimation(ui->lineEdit, "geometry");
        animation1->setDuration(10000); //动作时间
        animation1->setStartValue(ui->lineEdit->geometry()); //开始动作值
        animation1->setEndValue(QRect(200, 200, 100, 50)); //结束动作值

        QEasingCurve curve1; //动作曲线
        curve1.setType(QEasingCurve::OutBounce); //动作曲线方式
        curve1.setAmplitude(3.00); //回弹Bounce振幅
//        curve1.setOvershoot(2.70); //超调量,就是稳定量
//        curve1.setPeriod(4.90); //频率当量
        animation1->setEasingCurve(curve1);

        QPropertyAnimation *animation2 = new QPropertyAnimation(ui->pushButton, "geometry");
        animation2->setDuration(10000); //动作时间
        animation2->setStartValue(ui->pushButton->geometry()); //开始动作值
        animation2->setEndValue(QRect(100, 100, 70, 70)); //结束动作值

        QEasingCurve curve2; //动作曲线
        curve2.setType(QEasingCurve::InBack); //动作曲线方式
        curve2.setAmplitude(3.00); //回弹Bounce振幅
//        curve2.setOvershoot(2.70); //超调量,就是稳定量
//        curve2.setPeriod(4.90); //频率当量
        animation2->setEasingCurve(curve2);

        QPropertyAnimation *animation3 = new QPropertyAnimation(ui->pushButton_2, "geometry");
        animation3->setDuration(10000); //动作时间
        animation3->setStartValue(ui->pushButton_2->geometry()); //开始动作值
        animation3->setEndValue(QRect(300, 200, 150, 150)); //结束动作值

        QEasingCurve curve3; //动作曲线
        curve3.setType(QEasingCurve::InOutSine); //动作曲线方式
        curve3.setAmplitude(3.00); //回弹Bounce振幅
//        curve3.setOvershoot(2.70); //超调量,就是稳定量
//        curve3.setPeriod(4.90); //频率当量
        animation3->setEasingCurve(curve3);

        animation1->setLoopCount(-1); //动作次数,如果为-1表示一直循环
        animation2->setLoopCount(-1); //动作次数,如果为-1表示一直循环
        animation3->setLoopCount(-1); //动作次数,如果为-1表示一直循环

        QParallelAnimationGroup *group = new QParallelAnimationGroup;
        group->addAnimation(animation1);
        group->addAnimation(animation2);
        group->addAnimation(animation3);
        group->start();

        //this->close();
    }

    qDebug() << event->text() << "has been pressed";
}

效果如下:

多谢,亲爱的美美。

猜你喜欢

转载自blog.csdn.net/islinyoubiao/article/details/113750717