QPropertyAnimation 的用法

来源:互联网 发布:php培训课程安排 编辑:程序博客网 时间:2024/06/05 05:06
void loginDlg::showAnimation(bool isShow){    if (0 == m_anim1)    {        m_anim1 = new QPropertyAnimation(this, "windowOpacity");        m_anim1->setDuration(1000);        m_anim1->setEasingCurve(QEasingCurve::OutQuad);        m_animGroup.addAnimation(m_anim1);    }    if (0 == m_anim2)    {        m_anim2 = new QPropertyAnimation(this, "geometry");        m_anim2->setDuration(200);        m_anim2->setEasingCurve(QEasingCurve::OutCurve);        m_animGroup.addAnimation(m_anim2);    }    QRect startR, endR;    startR.setLeft(m_rect.left());    startR.setTop(m_rect.top() + m_rect.height()/2);    startR.setWidth(width());    startR.setHeight(0);    endR.setLeft(m_rect.left());    endR.setTop(m_rect.top());    endR.setWidth(width());    endR.setHeight(height());    if (isShow)    {        m_anim1->setStartValue(0);        m_anim1->setEndValue(1);        m_anim2->setStartValue(startR);        m_anim2->setEndValue(endR);    }    else    {        m_anim2->setStartValue(endR);        m_anim2->setEndValue(startR);        m_anim1->setStartValue(1);        m_anim1->setEndValue(0);    }    m_animGroup.start(QPropertyAnimation::KeepWhenStopped);

windowOpacity和gemotry 分别是 透明度和 rect的动画,,

结束动画可以用QTimer来定义一个时间,让动画结束之后再关闭

showAnimation(false);
 QTimer::singleShot(1000, this, SLOT(accept()));

原创粉丝点击