属性动画QPropertyAnimation

widget.h

#include "widget.h"
#include "ui_widget.h"
#include <QGraphicsColorizeEffect>
#include <QGraphicsOpacityEffect>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    propertyAnimation = new QPropertyAnimation(ui->geometryWidget,"geometry");
    //设置动画起始值、关键值、终止值;
    propertyAnimation->setStartValue(QRect(0,0,100,100));
    propertyAnimation->setKeyValueAt(0.5,QRect(0,400,200,200));
    propertyAnimation->setEndValue(QRect(600,400,200,200));
    //设置动画时常;
    propertyAnimation->setDuration(2000);
    //设置动画循环周期;
    propertyAnimation->setLoopCount(1);
    //设置动画缓和曲线;动画运动速度曲线;
    propertyAnimation->setEasingCurve(QEasingCurve::InOutCubic);
    
    //设置颜色动画;
    QGraphicsColorizeEffect *graphicsColorizeEffect = new QGraphicsColorizeEffect(this);
    ui->colorWidget->setGraphicsEffect(graphicsColorizeEffect);
    propertyAnimation1 = new QPropertyAnimation(graphicsColorizeEffect,"color");
    propertyAnimation1->setStartValue(QColor(Qt::black));
    propertyAnimation1->setEndValue(QColor(Qt::red));
    propertyAnimation1->setDuration(4000);
    
    //不透明度动画
    QGraphicsOpacityEffect *graphicsOpacityEffect = new QGraphicsOpacityEffect(this);
    ui->colorWidget->setGraphicsEffect(graphicsOpacityEffect);
    propertyAnimation2 = new QPropertyAnimation(graphicsOpacityEffect,"opacity");
    propertyAnimation2->setStartValue(0.0);
    propertyAnimation2->setEndValue(1.0);
    propertyAnimation2->setDuration(2000);
    
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    propertyAnimation->start();
    propertyAnimation2->start();
}

void Widget::on_pushButton_2_clicked()
{
    propertyAnimation1->start();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值