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); effect->setOpacity(1.0); ui->welcomePage->setGraphicsEffect(effect); QPropertyAnimation * anim = new QPropertyAnimation(ui->welcomePage); anim->setPropertyName("opacity"); anim->setTargetObject(effect); anim->setDuration(500); anim->setStartValue(effect->opacity()); anim->setEndValue(0.0); anim->setEasingCurve(QEasingCurve::OutQuad); anim->start(QAbstractAnimation::DeleteWhenStopped); 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
-
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.