Qt 简单动画demo

        //组合动画  
        this->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint); //无边框
        this->setAttribute(Qt::WA_TranslucentBackground, true);

        this->setGeometry(QApplication::desktop()->frameGeometry());
        QRect availableGeometry = QApplication::desktop()->availableGeometry();

        QLabel *temp = new QLabel(this);
        temp->setGeometry(this->geometry());
        temp->setPixmap(m_pixmap);
        QSize size = this->size();
        int m_duration = 800;

        //位置
        QPropertyAnimation *posAnimation = new QPropertyAnimation(temp, "pos");
        connect(posAnimation,SIGNAL(finished()),this,SLOT(close()));
        posAnimation->setDuration(m_duration);
        posAnimation->setKeyValueAt(0,QPoint(0,0));
        posAnimation->setKeyValueAt(0.15, QPoint(size.width()*0.09,size.height()*0.01));
        posAnimation->setKeyValueAt(0.5, QPoint(size.width()*0.25,size.height()*0.1));
        posAnimation->setKeyValueAt(0.8, QPoint(size.width()*0.45,size.height()*0.5));
        posAnimation->setKeyValueAt(1, QPoint(size.width()*0.5,size.height()));
        posAnimation->setEndValue(QPoint(size.width()*0.5-25,availableGeometry.height()-111));
        posAnimation->setEasingCurve(QEasingCurve::OutInQuad);
        posAnimation->start();

        //大小
        QPropertyAnimation *SizeAnimation = new QPropertyAnimation(temp, "size");
        QRect rect = this->rect();
        SizeAnimation->setDuration(m_duration);
        SizeAnimation->setKeyValueAt(0,QSize(rect.width(),rect.height()));
        SizeAnimation->setKeyValueAt(1, QSize(50,50));
        SizeAnimation->setEndValue(QSize(50,50));
        posAnimation->setEasingCurve(QEasingCurve::OutInQuad);
        SizeAnimation->start();

        //透明度
        QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect();
        m_section_btn->hide();
        m_all_btn->hide();
        m_setting_btn->hide();
        m_return_btn->hide();
        opacityEffect->setOpacity(1);
        temp->setGraphicsEffect(opacityEffect);
        QPropertyAnimation *opacityAnimation = new QPropertyAnimation(opacityEffect, "opacity");
        connect(opacityAnimation,SIGNAL(finished()),this,SLOT(close()));
        opacityAnimation->setDuration(m_duration);
        opacityAnimation->setStartValue(0.8);
        opacityAnimation->setEndValue(0.4);
        opacityAnimation->start();

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

大小
QPropertyAnimation *animation = new QPropertyAnimation(temp, "size");
connect(animation,SIGNAL(finished()),this,SLOT(close()));
QRect rect = this->rect();
animation->setDuration(3000);
animation->setKeyValueAt(0,QSize(rect.width(),rect.height()));

animation->setKeyValueAt(1, QSize(rect.width()/2,rect.height()/2));
animation->setEndValue(QSize(rect.width()/2,rect.height()/2));
animation->start();

----------------------------------------------------------------
非子窗口的透明度设置
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect();
opacityEffect->setOpacity(1);
temp->setGraphicsEffect(opacityEffect);
QPropertyAnimation *animation1 = new QPropertyAnimation(opacityEffect, "opacity");
connect(animation1,SIGNAL(finished()),this,SLOT(close()));
animation1->setDuration(2000);
animation1->setStartValue(1);
animation1->setEndValue(0.5);
animation1->start();



--------坐标-------------------------------------------
/*QPropertyAnimation *animation = new QPropertyAnimation(temp, "geometry");
//connect(animation,SIGNAL(finished()),this,SLOT(close()));
QRect rect = this->rect();
animation->setDuration(2000);
animation->setKeyValueAt(0,this->rect());
animation->setKeyValueAt(0.2,QRect(rect.width()*0.4,50,rect.width()/2,rect.height()/2));
animation->setKeyValueAt(0.4,QRect(rect.width()*0.3,50+rect.width()*0.1,rect.width()*0.4,rect.height()*0.4));
animation->setKeyValueAt(0.6,QRect(rect.width()*0.15,50+rect.width()*0.25,rect.width()*0.3,rect.height()*0.3));
animation->setKeyValueAt(0.8,QRect(70,50+rect.width()*0.45,rect.width()*0.2,rect.height()*0.2));
animation->setKeyValueAt(1, QRect(50,availableGeometry.height()-30,50, 50));
animation->setEndValue(QRect(50,availableGeometry.height()-111,70, 70));
animation->start();
animation->setEasingCurve(QEasingCurve::InOutQuad);*/

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  透明度

    QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
    animation->setDuration(300);
    animation->setStartValue(0);
    animation->setEndValue(1);
    animation->start();






  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值