QPropertyAnimation渐隐动画

来源:互联网 发布:宁波数据分析招聘 编辑:程序博客网 时间:2024/06/05 15:38

显隐是动画效果里比较常见的,一定要学会哟。


1、一般显隐动画:

虽然说QWidget没有opacity属性,但是却有windowOpacity属性。

上代码:
#include <QPropertyAnimation>


QPropertyAnimation *m_animation;


m_animation = new QPropertyAnimation(this, "windowOpacity");

m_animation->setStartValue(1);

m_animation->setEndValue(0);

m_animation->setDuration(1000);

m_animation->setEasingCurve(QEasingCurve::Linear);//动画效果

connect(m_animation, SIGNAL(finished()), this, SLOT(onAnimation()));//做了简单的处理,这个槽是根据需要写的


2、特殊情况:

有时,我们会遇到特殊情况,特别是和QGraphics体系混编的时候,有时如上述所做是不能解决问题的。

QGraphics体系里面显隐属性opacity,下面给出新的解决方案:

上代码:

#include <QGraphicsOpacityEffect>

#include <QPropertyAnimation>


QPropertyAnimation *m_animation;

QGraphicsOpacityEffect* m_widgetOpacity;


m_widgetOpacity = new QGraphicsOpacityEffect(this);

m_widgetOpacity->setOpacity(1.0);

this->setGraphicsEffect(m_widgetOpacity);

m_animation = new QPropertyAnimation(m_widgetOpacity,"opacity",this);

m_animation->setStartValue(1);

m_animation->setEndValue(0);

m_animation->setDuration(1000);

m_animation->setEasingCurve(QEasingCurve::Linear);//动画效果

connect(m_animation, SIGNAL(finished()), this, SLOT(onAnimation()));


0 0
原创粉丝点击