Qt 简单动画demo

来源:互联网 发布:linux命令行退出全屏 编辑:程序博客网 时间:2024/05/16 11:20
        //组合动画          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 0
原创粉丝点击