Important: Please read the Qt Code of Conduct -

QPropertyAnimation menubar

  • Hello,
    I have a QMainWindow class, i want to show/hide the menubar with an slow animation, because she's shown and hidden immediately. There is a QPropertyAnimation class, but i dont how to use this with a menubar

  • Hi @Yacinoben

    I think that you need to use the QPropertyAnimation with QGraphicsOpacityEffect:

    Here is a simple animation example with QPushButton:

    #include "mainwindow.h"
    #include <QApplication>
    #include <QGraphicsOpacityEffect>
    #include <QPropertyAnimation>
    #include <QPushButton>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        MainWindow w;
        QGraphicsOpacityEffect *opacity = new QGraphicsOpacityEffect;
        QPropertyAnimation *anim = new QPropertyAnimation( opacity, "opacity" );
        QPushButton *animatedButton = new QPushButton( "Animation", &w );
        animatedButton->setGraphicsEffect( opacity );
        anim->setDuration( 2000 );
        anim->setStartValue( 0.1 );
        anim->setEndValue( 1.0 );
        anim->setEasingCurve( QEasingCurve::InCubic );
        return a.exec();

    You can get inspired from this example to achieve your animation.

    To go further i advise you to read the Qt Animation overview

Log in to reply