fix: clip item background painting to prevent border overflow in high…#443
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideClips 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 behaviorclassDiagram
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
Flow diagram for PluginItemDelegate paint with clippingflowchart 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]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider wrapping the
setClipRect(boption.rect)call withpainter->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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
… 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
6587e3d to
775e8d7
Compare
deepin pr auto review这段代码修改主要针对高DPI(Dots Per Inch)显示环境下,Qt绘图可能出现的溢出问题进行了修复。以下是对该代码的详细审查意见: 1. 语法逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
总结与改进建议这是一个高质量的修复补丁,主要解决了高DPI下的渲染瑕疵。 建议:
|
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
… 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: