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. Use animation and drop-shadow in sequence
Forum Updated to NodeBB v4.3 + New Features

Use animation and drop-shadow in sequence

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.1k Views 2 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    Hi,

    i want a drop-shadow-widget. I want to mix it with a fade-in effect. But both effects are not possible. Any solution how to set two effects?

    Here's the code

    WidgetDecorator::WidgetDecorator(QObject* parent)
        : QObject(parent) {}
    
    void WidgetDecorator::addDropShadow(QWidget* widget) {
        // widget->window()->setAttribute(Qt::WA_TranslucentBackground);
        // widget->window()->setla //layout()->setMargin(50);
        QGraphicsDropShadowEffect* ef = new QGraphicsDropShadowEffect(widget);
        ef->setBlurRadius(10);
        ef->setOffset(20);
        ef->setColor(QColor(0, 0, 0, 255));
        widget->setGraphicsEffect(ef);
    }
    
    void WidgetDecorator::fadeInWidget(QWidget* widget) {
        QGraphicsOpacityEffect* mEffect = new QGraphicsOpacityEffect(widget);
        mEffect->setOpacity(1.0);
        widget->setGraphicsEffect(mEffect);
    
        QPropertyAnimation* animation = new QPropertyAnimation(mEffect, "opacity");
        animation->setDuration(500);
        animation->setStartValue(1.0);
        animation->setEndValue(0.0);
        // connect(animation,SIGNAL(finished()),this,SLOT(onAnimationFinished()));
        animation->start(QAbstractAnimation::DeleteWhenStopped);
        /*QSize size = widget->size();
    
        QPropertyAnimation* animation = new QPropertyAnimation(widget,"size");
        animation->setDuration(500);
        animation->setStartValue(QSize(0,0));
        animation->setEndValue(size);
        animation->start(QAbstractAnimation::DeleteWhenStopped);*/
    }
    
    void WidgetDecorator::fadeOutWidget(QWidget* widget) {
        QSize size = widget->size();
    
        QPropertyAnimation* animation = new QPropertyAnimation(widget, "size");
        animation->setDuration(1000);
        animation->setEndValue(QSize(0, 0));
        animation->setStartValue(size);
        animation->start(QAbstractAnimation::DeleteWhenStopped);
    }
    

    Now i want to call addDropShadow followed by fadeInWidget. But only the drop-shadow-effect is shown.
    How can i apply both?

    Thank you very much!!!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @jensen82 Try QParallelAnimationGroup.

      157

      1 Reply Last reply
      1
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        Hi,

        thank you. Why do i have to create a group? I have one Animation only. And one Effect.

        Now i want to call addDropShadow followed by fadeInWidget. 
        

        One Animation.

        J.HilkJ 1 Reply Last reply
        0
        • jensen82J jensen82

          Hi,

          thank you. Why do i have to create a group? I have one Animation only. And one Effect.

          Now i want to call addDropShadow followed by fadeInWidget. 
          

          One Animation.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @jensen82

          QParallelAnimationGroup you'll have to use, if you want multiple animations happen at the same time.

          If I understand you correctly, you want to start a different animation once the old one finished.

          You can chain them with signal/slots:

          // All your animations are named the same, so I'm renaming them in this example
          connect(animation1, &QPropertyAnimation::finished, [=]{animation2->start();});
          connect(animation2, &QPropertyAnimation::finished, [=]{animation3->start();});
          
          .....
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          4
          • jensen82J Offline
            jensen82J Offline
            jensen82
            wrote on last edited by
            #5

            Thank you very much!

            1 Reply Last reply
            0

            • Login

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