From 8a5bac149560840df69b59790710b853ecdb1579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A6=83=E6=9C=AC=E5=AD=A6?= Date: Fri, 19 Jul 2024 16:43:37 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E6=A0=B7=E5=BC=8F,=E9=80=82=E9=85=8D=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新滚动条样式,适配动画 Log: --- styleplugins/chameleon/chameleonstyle.cpp | 47 ++++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 497cc874..7b88cb7a 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -1422,7 +1422,17 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt frameRadius = qMin(height / 2, 4); } p->setBrush(getColor(opt, DPalette::ObviousBackground, w)); + p->setPen(Qt::NoPen); p->drawRoundedRect(opt->rect, frameRadius, frameRadius); + + QPen pen; + pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType + ? QColor(255, 255, 255, 0.15 * 255) + : QColor(0, 0, 0, 0.15 * 255)); + pen.setWidth(1); + p->setPen(pen); + p->setBrush(Qt::NoBrush); + p->drawRoundedRect(opt->rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius); } return; } @@ -1462,7 +1472,7 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt linear.setColorAt(0, startColor); linear.setColorAt(1, endColor); linear.setSpread(QGradient::PadSpread); - p->setBrush(QBrush(linear)); + p->setBrush(startColor); if (progBar->textVisible) { QPainterPath pathRect; @@ -1470,7 +1480,25 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt QPainterPath pathRoundRect; pathRoundRect.addRoundedRect(opt->rect, frameRadius, frameRadius); QPainterPath inter = pathRoundRect.intersected(pathRect); + + QPainterPath clipPath; + clipPath.addRoundedRect(rect, frameRadius, frameRadius); + p->setClipPath(clipPath); + p->setClipping(true); p->drawPath(inter); + p->setClipping(false); + + QPen pen; + pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType + ? QColor(255, 255, 255, 0.3 * 255) + : QColor(0, 0, 0, 0.3 * 255)); + pen.setWidth(1); + p->setPen(pen); + p->setBrush(Qt::NoBrush); + p->setClipping(true); + p->drawRoundedRect(rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius); + p->setClipping(false); + } else { //进度条高度 <= 8px && 进度条宽度 <= 8px && value有效 if (rect.height() <= ProgressBar_MinimumStyleHeight && @@ -1496,8 +1524,23 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt path2.arcTo(endRect, 90, -180); p->drawPath(path2); } - } else + } else { + QPainterPath clipPath; + clipPath.addRoundedRect(opt->rect, frameRadius, frameRadius); + p->setClipPath(clipPath); + p->setClipping(true); p->drawRoundedRect(rect, frameRadius, frameRadius); + p->setClipping(false); + + QPen pen; + pen.setColor(QColor(0, 0, 0, 0.3 * 255)); + pen.setWidth(1); + p->setPen(pen); + p->setBrush(Qt::NoBrush); + p->setClipping(true); + p->drawRoundedRect(rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius); + p->setClipping(false); + } } } return;