Search code examples
c++qtanimationqwidget

Qt 4.7.4 QPropertyAnimation not working


I'm trying to have animation on a button click event. But somehow the animation is not working. I have referred the Qt reference docs, but could not find the root cause which is causing the issue

Below is sample code :

void MainWindow::AnimationClick()
{
    // define toolbar y movement positions for animation
    TOOLBAR_Y_SHOWN = 0;
    TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
    m_AnimatedWidget = new AnimatedWidget(this);

    QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);

    m_ani->setDuration(500);

    m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
    m_ani->setEasingCurve(QEasingCurve::InBack);

    m_ani->start();
}

With the above implementation nothing is happening on the click event. Any suggestions , Thanks.


Solution

  • I got it. I was not allowing the m_AnimatedWidget to show upon the screen. Below is the edited snippet.

    void MainWindow::AnimationClick()
    {
        // define toolbar y movement positions for animation
        TOOLBAR_Y_SHOWN = 0;
        m_AnimatedWidget = new AnimatedWidget(this);
        TOOLBAR_Y_HIDDEN = -m_AnimatedWidget->height();
    
    
        QPropertyAnimation *m_ani = new QPropertyAnimation(m_AnimatedWidget, "pos", this);
    
        m_ani->setDuration(5000);
    
        m_ani->setEndValue(QPoint(m_AnimatedWidget->pos().x(), TOOLBAR_Y_HIDDEN));
        m_ani->setEasingCurve(QEasingCurve::InBack);
    
        m_ani->start();
        m_AnimatedWidget->show();
    }