Solved Use animation and drop-shadow in sequence
-
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!!!
-
-
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.
-
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();}); .....
-
Thank you very much!