void
CommonDialog::closeEvent(QCloseEvent *event)
{
m_impl->closeWithAnimation(this, event);
}
class CommonDialog::Impl {
public:
...
void closeWithAnimation(CommonDialog *dlg, QCloseEvent *event)
{
if (!event)
return dlg->closeEvent(event);
event->ignore();
auto graphicsOpacityEffect = new QGraphicsOpacityEffect(dlg);
graphicsOpacityEffect->setOpacity(1.0);
dlg->setGraphicsEffect(graphicsOpacityEffect);
auto opacityAnimation = new QPropertyAnimation(graphicsOpacityEffect, "opacity");
opacityAnimation->setDuration(m_exitAnimationTimeout);
opacityAnimation->setStartValue(1.0);
opacityAnimation->setEndValue(0.0);
opacityAnimation->setEasingCurve(QEasingCurve::InBounce);
opacityAnimation->start();
connect(opacityAnimation, &QPropertyAnimation::finished, dlg, &QDialog::accept);
}
void setExitAnimationTimeout(int timeout)
{
m_exitAnimationTimeout = timeout;
}
private:
int m_exitAnimationTimeout = 300;
};