fix: ISSUE #I6CU7C 下载完成时,即使主窗口被遮挡,下载列表按钮动画效果仍显示在最上层

动画效果 WaterDrop widget 未设置父对象,使用全局坐标映射显示在按钮位置

Log: 对 WaterDrop 添加父对象,与下载列表按钮同级,为标题栏布局子控件,以此限制动画显示范围仅在标题栏内
This commit is contained in:
zty199 2023-02-11 19:19:09 +08:00
parent 48d551424a
commit da03261cbb
2 changed files with 15 additions and 11 deletions

View File

@ -9,7 +9,7 @@ ProgressButton::ProgressButton(QWidget *parent)
: QWidget{parent} : QWidget{parent}
{ {
// this->setWindowFlags(Qt::FramelessWindowHint); // this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true); // this->setAttribute(Qt::WA_TranslucentBackground, true);
setMinimumWidth(36); setMinimumWidth(36);
setMinimumHeight(36); setMinimumHeight(36);
svgPath = ""; svgPath = "";
@ -99,8 +99,8 @@ void ProgressButton::setProgress(int progress)
{ {
buttonState = state::closeProgress; buttonState = state::closeProgress;
update(); update();
auto waterDrop = new WaterDrop(); WaterDrop *waterDrop = new WaterDrop(parentWidget());
waterDrop->move(this->mapToGlobal(this->rect().center())); waterDrop->move(geometry().center());
waterDrop->show(); waterDrop->show();
} }
repaint(); repaint();
@ -159,11 +159,13 @@ WaterDrop::WaterDrop(QWidget *parent)
: QWidget(parent), m_waterDropAnimation(nullptr), m_animationRadius(0) : QWidget(parent), m_waterDropAnimation(nullptr), m_animationRadius(0)
{ {
this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2)); this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2));
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool); // this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
this->setAttribute(Qt::WA_TranslucentBackground); // this->setAttribute(Qt::WA_TranslucentBackground);
this->setAttribute(Qt::WA_DeleteOnClose); // this->setAttribute(Qt::WA_DeleteOnClose);
m_waterDropAnimation = new QVariantAnimation(this); m_waterDropAnimation = new QVariantAnimation(this);
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40)))); // m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::deleteLater);
} }
// 把鼠标点击的点转换为圆心点坐标 // 把鼠标点击的点转换为圆心点坐标
@ -179,9 +181,9 @@ void WaterDrop::show()
m_waterDropAnimation->setEndValue(RADIUS); m_waterDropAnimation->setEndValue(RADIUS);
m_waterDropAnimation->setDuration(350); m_waterDropAnimation->setDuration(350);
connect(m_waterDropAnimation, &QVariantAnimation::valueChanged, this, &WaterDrop::onRaduisChanged); connect(m_waterDropAnimation, &QVariantAnimation::valueChanged, this, &WaterDrop::onRadiusChanged);
connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::close); connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::close);
m_waterDropAnimation->start(); m_waterDropAnimation->start(QVariantAnimation::DeleteWhenStopped);
QWidget::show(); QWidget::show();
} }
@ -194,9 +196,11 @@ void WaterDrop::paintEvent(QPaintEvent *event)
pen.setWidth(5); pen.setWidth(5);
painter.setPen(pen); painter.setPen(pen);
painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius); painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
QWidget::paintEvent(event);
} }
void WaterDrop::onRaduisChanged(QVariant value) void WaterDrop::onRadiusChanged(QVariant value)
{ {
m_animationRadius = value.toInt(); m_animationRadius = value.toInt();
update(); update();

View File

@ -61,7 +61,7 @@ public:
private: private:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void onRaduisChanged(QVariant value); void onRadiusChanged(QVariant value);
private: private:
class QVariantAnimation* m_waterDropAnimation; class QVariantAnimation* m_waterDropAnimation;