From 22a5abb8e8818ae295f09e5cd8c2fd1fd8297ac7 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Mon, 9 Mar 2026 10:16:29 +0800 Subject: [PATCH] fix(style): fix visual artifacts after deselecting list items at high DPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use setClipRect to limit drawing area and prevent antialiasing artifacts from extending beyond item boundaries. 使用setClipRect限制绘制区域,防止反锯齿伪影超出item边界。 Log: 修复高DPI缩放下列表项取消选中后的视觉残留问题 PMS: BUG-332513 Influence: 修复后在125%及更高DPI缩放下,列表项取消选中后不再出现视觉残留横线,同时保持圆角平滑效果,不影响其他项的正常显示。 --- styleplugins/chameleon/chameleonstyle.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 8577d77a..63b70621 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017 - 2024 UnionTech Software Technology Co., Ltd. + * SPDX-FileCopyrightText: 2017 - 2026 UnionTech Software Technology Co., Ltd. * SPDX-License-Identifier: LGPL-3.0-or-later */ #include "chameleonstyle.h" @@ -352,17 +352,20 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti int frame_radius = DStyle::pixelMetric(PM_FrameRadius, opt, w); if (vopt->state & QStyle::State_Selected) { - QRect select_rect = opt->rect; + QRect select_rect = opt->rect; - if (!vopt->showDecorationSelected) { - select_rect = proxy()->subElementRect(QStyle::SE_ItemViewItemText, opt, w); - } + if (!vopt->showDecorationSelected) { + select_rect = proxy()->subElementRect(QStyle::SE_ItemViewItemText, opt, w); + } - p->setPen(Qt::NoPen); - p->setBrush(getColor(opt, QPalette::Highlight)); - p->setRenderHint(QPainter::Antialiasing); - p->drawRoundedRect(select_rect, frame_radius, frame_radius); - return; + p->save(); + p->setPen(Qt::NoPen); + p->setClipRect(opt->rect); + p->setBrush(getColor(opt, QPalette::Highlight)); + p->setRenderHint(QPainter::Antialiasing); + p->drawRoundedRect(select_rect, frame_radius, frame_radius); + p->restore(); + return; } else { if (vopt->backgroundBrush.style() != Qt::NoBrush) { p->save();