Qt笔记_动画

动画框架


创建平滑的、具有动画效果的GUI界面
帮助关键字The Animation Framework;


使用QPropertyAnimation类
头文件 < QPropertyAnimation>

    QApplication app(argc, argv);
    QPushButton button("Animated Button");
    button.show();
    QPropertyAnimation animation(&button, "geometry");
    animation.setDuration(10000);
//    animation.setStartValue(QRect(0, 0, 120, 30));
//    animation.setEndValue(QRect(250, 250, 200, 60));
    animation.setKeyValueAt(0, QRect(0, 0, 120, 30));
    animation.setKeyValueAt(0.8, QRect(250, 250, 200, 60));
    animation.setKeyValueAt(1, QRect(0, 0, 120, 30));
    animation.start();
    return app.exec();

动画中可以使用pause()来暂停动画;使用resume()结束暂停;使用stop()来停止动画;setDirection()设置动画方向;setLoopCount()设置动画重复次数。

使用缓和曲线

QEasingCurve::OutBounce缓和曲线。
实现弹跳效果:

    QApplication app(argc, argv);
    QPushButton button("Animated Button");
    button.show();
    QPropertyAnimation animation(&button, "geometry");

    animation.setDuration(2000);
    animation.setStartValue(QRect(250, 0, 120, 30));
    animation.setEndValue(QRect(250, 300, 120, 30));
    animation.setEasingCurve(QEasingCurve::OutBounce);

    animation.start();
    return app.exec();

动画组

QParallelAnimationGroup并行动画组
QSequentialAnimationGroup串行动画组

	QApplication app(argc, argv);
    QPushButton button1("Animated Button");
    button1.show();
    QPushButton button2("Animated Button2");
    button2.show();
    // 按钮部件1的动画
    QPropertyAnimation *animation1 = new QPropertyAnimation(&button1, "geometry");
    animation1->setDuration(2000);
    animation1->setStartValue(QRect(250, 0, 120, 30));
    animation1->setEndValue(QRect(250, 300, 120, 30));
    animation1->setEasingCurve(QEasingCurve::OutBounce);
    // 按钮部件2的动画
    QPropertyAnimation *animation2 = new QPropertyAnimation(&button2, "geometry");
    animation2->setDuration(2000);
    animation2->setStartValue(QRect(400, 300, 120, 30));
    animation2->setEndValue(QRect(400, 300, 200, 60));
    // 并行动画组
    QParallelAnimationGroup group;
    group.addAnimation(animation1);
    group.addAnimation(animation2);
    group.start();

    return app.exec();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值