From c32bf23d3b0b92d731234a452f4f80345c20c0a8 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Mon, 9 Feb 2026 09:48:47 +0800 Subject: [PATCH] fix(style): adjust slider groove offset when no ticks are displayed When a slider has no tick marks, the groove now extends to the full width/height of the slider area without indentation at the ends. log: adjust slider groove offset when no ticks are displayed bug: PMS-299727 --- styleplugins/chameleon/chameleonstyle.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 8813797b..8577d77a 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -3772,20 +3772,24 @@ void ChameleonStyle::drawComplexControl(QStyle::ComplexControl cc, const QStyleO if (slider->orientation == Qt::Horizontal) { // 绘制最左边到滑块的位置的滑槽 qreal rectWidth = rectHandle.width() / 2.0; - p->drawLine(QPointF(rectGroove.left() + rectWidth, rectHandle.center().y()), QPointF(rectHandle.center().x(), rectHandle.center().y())); + // 只有当不绘制刻度线的时候,就不要给滑槽两边弄缩进 + qreal offset = (slider->tickPosition == QSlider::NoTicks) ? 0 : rectWidth; + p->drawLine(QPointF(rectGroove.left() + offset, rectHandle.center().y()), QPointF(rectHandle.center().x(), rectHandle.center().y())); // 绘制滑块到最右的位置的滑槽 pen.setColor(color); p->setPen(pen); - p->drawLine(QPointF(rectGroove.right() - rectWidth, rectHandle.center().y()), QPointF(rectHandle.center().x(), rectHandle.center().y())); + p->drawLine(QPointF(rectGroove.right() - offset, rectHandle.center().y()), QPointF(rectHandle.center().x(), rectHandle.center().y())); } else { // 绘制最上边到滑块的位置的滑槽 qreal rectWidth = rectHandle.height() / 2.0; - p->drawLine(QPointF(rectGroove.center().x(), rectGroove.bottom() - rectWidth), QPointF(rectGroove.center().x(), rectHandle.center().y())); + // 只有当不绘制刻度线的时候,就不要给滑槽两边弄缩进 + qreal offset = (slider->tickPosition == QSlider::NoTicks) ? 0 : rectWidth; + p->drawLine(QPointF(rectGroove.center().x(), rectGroove.bottom() - offset), QPointF(rectGroove.center().x(), rectHandle.center().y())); // 绘制滑块到最下的位置的滑槽 pen.setColor(color); p->setPen(pen); - p->drawLine(QPointF(rectGroove.center().x(), rectGroove.top() + rectWidth), QPointF(rectGroove.center().x(), rectHandle.center().y())); + p->drawLine(QPointF(rectGroove.center().x(), rectGroove.top() + offset), QPointF(rectGroove.center().x(), rectHandle.center().y())); } }