Important: Please read the Qt Code of Conduct -

Trying to have a QStackedWidget to fade in/out between page transitions

  • Hi everyone,

    I try to have a QStackedWidget switch between pages by using a fade in/out animation.

    I've tried several things to do so, but, expect for animating the windowOpacity (which fades out all the window, not only the widget I'd like to), I haven't found a solution.

    for now I use this code to try to get it work:

    @void MyWindow::switchToPage()
    qDebug() << "switching";

    QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(ui->welcomePage);
    QPropertyAnimation * anim = new QPropertyAnimation(ui->welcomePage);
    connect(anim, SIGNAL(finished()), this, SLOT(showNextPage()));


    if anyone has some idea, I'll be glad.

    Thanks in advance

  • I don't think there is a solution with the standard QStackedWidget on its own. The stacked widget switches between pages by using show() and hide() on the relevant child widgets. You could use the child widget QWidget::showEvent() and hideEvent() to have each widget fade itself in/out when shown/hidden.

  • Indeed, you're right,

    I've implemented my own per-widget transition to do the trick,

    Thanks a lot for the answer

  • Lifetime Qt Champion

    Great ! Would you share the code so other people interested in this topic can do the same ?

    Also, can you update the title as solved so everybody knows that it's all good ?

  • Code would be really nice, indeed.

Log in to reply