Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trying to have a QStackedWidget to fade in/out between page transitions
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 6.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fredaime
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fredaime
        wrote on last edited by
        #3

        Indeed, you're right,

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

        Thanks a lot for the answer

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • P Offline
            P Offline
            philk
            wrote on last edited by
            #5

            Code would be really nice, indeed.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved