Skip to content

fix: clip item background painting to prevent border overflow in high…#443

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Ivy233:fix/high-dpi-item-border-overflow
Mar 19, 2026
Merged

fix: clip item background painting to prevent border overflow in high…#443
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Ivy233:fix/high-dpi-item-border-overflow

Conversation

@Ivy233
Copy link
Contributor

@Ivy233 Ivy233 commented Mar 19, 2026

… DPI

When using fractional scaling (e.g. 125%), DStyle's PE_ItemBackground drawing could overflow the item rect boundary into the gap area between items, leaving a visible blue line artifact on the top edge of the middle item during hover state transitions.

Added painter->setClipRect(boption.rect) to constrain the background drawing within the adjusted item rect, preventing border overflow into the spacing gap between items.

fix: 修复高DPI下列表项背景绘制边框溢出问题

在使用非整数缩放(如125%)时,DStyle绘制PE_ItemBackground时边框会
溢出到列表项之间的间隙区域,导致鼠标从上往下滑过中间项时,其上边缘
出现蓝色残留线条。

通过在绘制前设置painter->setClipRect(boption.rect),将背景绘制限制 在调整后的项矩形范围内,防止边框溢出到项间距区域。

PMS: BUG-336463

Summary by Sourcery

Bug Fixes:

  • Prevent item background borders from overflowing into the spacing gap between dock items at fractional display scaling (e.g., 125%), which caused visible blue line artifacts on hover transitions.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Clips the plugin item delegate’s background painting to the adjusted item rect so that DStyle’s PE_ItemBackground does not overflow into the gap between items on high-DPI fractional scaling.

Class diagram for updated PluginItemDelegate paint behavior

classDiagram
    class PluginItemDelegate {
        +QAbstractItemView m_view
        +paint(QPainter* painter, QStyleOptionViewItem const& option, QModelIndex const& index) void
    }

    class QPainter {
        +setClipRect(QRect const& rect) void
        +draw...() void
    }

    class QStyleOptionViewItem {
        +QRect rect
    }

    class QRect {
        +adjust(int left, int top, int right, int bottom) void
    }

    class ItemSpacing {
        +int top
        +int bottom
    }

    PluginItemDelegate --> QAbstractItemView : uses m_view
    PluginItemDelegate --> QPainter : uses
    PluginItemDelegate --> QStyleOptionViewItem : uses option
    PluginItemDelegate --> ItemSpacing : uses itemSpacing
    QStyleOptionViewItem --> QRect : has rect
    PluginItemDelegate ..> QRect : adjusts and sets clipRect via painter
    QPainter ..> QRect : setClipRect
Loading

Flow diagram for PluginItemDelegate paint with clipping

flowchart TD
    A[paint called with painter, option, index] --> B[Copy option to boption]
    B --> C[Compute itemSpacing]
    C --> D{itemSpacing.top != 0 or itemSpacing.bottom != 0}
    D -- yes --> E[Adjust boption.rect by itemSpacing.top and -itemSpacing.bottom]
    D -- no --> F[Keep boption.rect unchanged]
    E --> G[Set painter clip rect to boption.rect]
    F --> G[Set painter clip rect to boption.rect]
    G --> H[Determine bgColor and textColor based on currentIndex and state]
    H --> I[Draw item background using DStyle PE_ItemBackground]
    I --> J[Draw item contents]
    J --> K[Return from paint]
Loading

File-Level Changes

Change Details Files
Constrain item background painting to the adjusted item rectangle to avoid border overflow artifacts on high-DPI fractional scaling.
  • After adjusting boption.rect for top/bottom item spacing, set the painter’s clip rectangle to that adjusted rect before any further painting.
  • Document the reason for clipping with a brief comment describing the high-DPI DStyle border overflow issue.
plugins/dde-dock/common/pluginitemdelegate.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Ivy233 Ivy233 requested review from 18202781743 and BLumia March 19, 2026 12:15
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • Consider wrapping the setClipRect(boption.rect) call with painter->save() / painter->restore() to avoid unintentionally constraining the clip region for any subsequent painting operations in this delegate.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider wrapping the `setClipRect(boption.rect)` call with `painter->save()` / `painter->restore()` to avoid unintentionally constraining the clip region for any subsequent painting operations in this delegate.

## Individual Comments

### Comment 1
<location path="plugins/dde-dock/common/pluginitemdelegate.cpp" line_range="41" />
<code_context>
         boption.rect.adjust(0, itemSpacing.top, 0, -itemSpacing.bottom);
     }
+    // 限制绘制范围,防止高DPI下DStyle绘制ItemBackground边框溢出到gap区域
+    painter->setClipRect(boption.rect);

     QColor bgColor, textColor;
</code_context>
<issue_to_address>
**issue (bug_risk):** Consider saving/restoring the painter or intersecting with the existing clip to avoid leaking the clip state.

`setClipRect` replaces any existing clip on the painter and the new clip will persist for later painting unless reset, which can cause subtle rendering issues if other code relies on a different clip. To avoid leaking painter state, either:

1) Wrap this section in `painter->save(); ... painter->restore();`, or
2) Use the overload with `Qt::IntersectClip` to narrow the clip while preserving any existing region.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

18202781743
18202781743 previously approved these changes Mar 19, 2026
… DPI

When using fractional scaling (e.g. 125%), DStyle's PE_ItemBackground
drawing could overflow the item rect boundary into the gap area between
items, leaving a visible blue line artifact on the top edge of the
middle item during hover state transitions.

Added painter->setClipRect(boption.rect) to constrain the background
drawing within the adjusted item rect, preventing border overflow into
the spacing gap between items.

fix: 修复高DPI下列表项背景绘制边框溢出问题

在使用非整数缩放(如125%)时,DStyle绘制PE_ItemBackground时边框会
溢出到列表项之间的间隙区域,导致鼠标从上往下滑过中间项时,其上边缘
出现蓝色残留线条。

通过在绘制前设置painter->setClipRect(boption.rect),将背景绘制限制
在调整后的项矩形范围内,防止边框溢出到项间距区域。

PMS: BUG-336463
@Ivy233 Ivy233 force-pushed the fix/high-dpi-item-border-overflow branch from 6587e3d to 775e8d7 Compare March 19, 2026 12:59
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改主要针对高DPI(Dots Per Inch)显示环境下,Qt绘图可能出现的溢出问题进行了修复。以下是对该代码的详细审查意见:

1. 语法逻辑审查

  • 正确性:代码逻辑是正确的。
    • painter->save()painter->restore() 成对出现,确保了绘图状态的隔离,不会影响后续的绘制操作。
    • painter->setClipRect(boption.rect, Qt::IntersectClip) 正确设置了裁剪区域,将绘制内容限制在 boption.rect 指定的矩形范围内。
  • 上下文:修改位于 paint 函数中,在调用 drawPrimitive 绘制背景之前设置裁剪,时机正确,符合Qt绘图的常规做法。

2. 代码质量审查

  • 注释质量// 限制绘制范围,防止高DPI下DStyle绘制ItemBackground边框溢出到gap区域 注释清晰明了,准确解释了这段代码的用途和背景(高DPI适配),值得肯定。
  • 代码风格:符合Qt的编码规范,缩进和格式良好。
  • 版权年份修改:diff中第一行将版权年份从 2023 更新到了 2026。这通常是合理的,表示代码将持续维护到该年份,但请确认 2026 是否为预期的年份(通常如果是当前年份修改,可能会写 20242023-2024;如果是长期规划,写未来年份也可以)。

3. 代码性能审查

  • 性能影响轻微
    • painter->save()painter->restore() 会涉及绘图栈状态的保存与恢复,有一定的开销,但在 paint 事件中这种开销是必要的且通常可以接受。
    • setClipRect 会增加图形系统的裁剪计算,但在处理溢出问题时,这是比调整几何计算更通用且安全的方案。
  • 优化建议:无需优化。为了保证UI渲染的正确性(避免视觉瑕疵),这点性能损耗是值得的。

4. 代码安全审查

  • 安全性安全
    • 不涉及内存操作、字符串处理或外部输入,因此不存在缓冲区溢出或注入风险。
    • 使用 Qt::IntersectClip 而不是 Qt::ReplaceClipQt::NoClip 是更安全的选择。如果父级调用栈中已经设置了裁剪区域,IntersectClip 会取交集,确保不会意外绘制到父级禁止绘制的区域之外。

总结与改进建议

这是一个高质量的修复补丁,主要解决了高DPI下的渲染瑕疵。

建议:

  1. 确认版权年份:请再次确认将版权年份改为 2026 是否符合项目规范。如果只是常规的年度维护,通常建议更新为当前年份(如 2024)或范围(如 2016 - 2024)。除非有特定的长期规划原因,否则写较远的未来年份可能会引起困惑。
  2. 保持现状:代码逻辑和实现方式是目前解决此类问题的最佳实践,无需进一步修改。

@Ivy233 Ivy233 requested a review from 18202781743 March 19, 2026 13:00
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, Ivy233

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Ivy233
Copy link
Contributor Author

Ivy233 commented Mar 19, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 19, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 9711b96 into linuxdeepin:master Mar 19, 2026
10 of 11 checks passed
@Ivy233 Ivy233 deleted the fix/high-dpi-item-border-overflow branch March 19, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants