Repository navigation
fix(editor): render dropdown arrows as vectors to keep them sharp under fractional scaling - #734
Conversation
Reviewer's GuideImplementationReview the icon rebuild path: normal-state arrows now render from the SVG at the current icon density instead of reusing the construction-time bitmap, while pressed-state rendering remains unchanged.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/widgets/ddropdownmenu.cpp" line_range="418" />
<code_context>
+ // 原实现使用构造期按当时缩放比缓存的位图,分数倍缩放比在窗口创建后
+ // 才被主题层异步应用,缓存位图被拉伸显示而模糊(PMS 171749)。
+ // 注意:不可改用 devicePixelRatioF() 自行光栅化——分数缩放下该值不可靠。
+ const QString arrowTheme = (dpalette.color(QPalette::Background).lightness() < 128) ? "dark" : "light";
+ QSvgRenderer svgRender(QString(":/images/dropdown_arrow_%1.svg").arg(arrowTheme));
+ svgRender.render(&painter, QRectF(fontWidth, (totalHeigth-iconH)/2.0, iconW, iconH));
</code_context>
<issue_to_address>
**Arrows use the wrong theme color**
When the editor theme differs from the button or application palette, `createIcon()` selects the SVG from the button palette, while `BottomBar::setPalette()` assigns the application palette to the buttons and supplies the editor theme separately to `setTheme()`. The normal-state arrow therefore uses the wrong light/dark asset and can lose contrast against the bottom bar.
Select the normal-state SVG from the theme supplied to `setTheme()` rather than from the button palette.
Also at `src/widgets/ddropdownmenu.cpp:419`.
</issue_to_address>
### Comment 2
<location path="src/widgets/bottombar.cpp" line_range="72-73" />
<code_context>
+ m_formatMenu->setTheme(theme);
+ };
+ const auto hookScreen = [this, refreshArrowTheme](QScreen *screen) {
+ connect(screen, &QScreen::logicalDotsPerInchChanged, this, refreshArrowTheme, Qt::QueuedConnection);
+ connect(screen, &QScreen::geometryChanged, this, refreshArrowTheme, Qt::QueuedConnection);
+ };
+ for (QScreen *screen : QGuiApplication::screens()) {
</code_context>
<issue_to_address>
**Arrows blur after moving screens**
When the window moves between screens with different scale factors and neither screen's DPI or geometry changes, `BottomBar` refreshes icons only on screen DPI or geometry changes, so moving the window triggers no refresh and the cached icons retain the previous screen's density. The arrows appear blurry on the destination screen.
Refresh the icons when the window changes screens instead of relying only on screen DPI and geometry signals.
Also at `src/widgets/bottombar.cpp:78`.
</issue_to_address>
### Comment 3
<location path="src/widgets/bottombar.cpp" line_range="78" />
<code_context>
+ for (QScreen *screen : QGuiApplication::screens()) {
+ hookScreen(screen);
+ }
+ connect(qApp, &QGuiApplication::screenAdded, this, hookScreen);
+ // 异步落地兜底:启动后延迟刷新一次
+ QTimer::singleShot(1500, this, refreshArrowTheme);
</code_context>
<issue_to_address>
**New screen leaves arrows stale**
When a screen is added after startup and emits no later geometry or logical-DPI change, `hookScreen` only subscribes to later screen changes; it does not refresh the icons for the `screenAdded` event itself. If a newly attached screen already has its final geometry and DPI when it is added, the one-shot startup timer has already run, so the existing icons keep their old-density pixmaps and appear blurry on that screen.
Refresh the arrows when `screenAdded` fires, in addition to subscribing to that screen’s later changes.
</issue_to_address>
### Comment 4
<location path="src/widgets/ddropdownmenu.cpp" line_range="411-412" />
<code_context>
//qDebug()<<"==================="<<arrowPixmap.rect().height();
- painter.drawPixmap(QRectF(fontWidth,(totalHeigth-iconH)/2,iconW,iconH),arrowPixmap,arrowPixmap.rect());
+ if (m_bPressed) {
+ painter.drawPixmap(QRectF(fontWidth,(totalHeigth-iconH)/2,iconW,iconH),arrowPixmap,arrowPixmap.rect());
+ } else {
+ // 箭头直接按当前图标密度矢量渲染,与文字密度保持一致。
</code_context>
<issue_to_address>
**Pressed arrows blur during scaling**
When a dropdown is pressed before the fractional scale factor has finished applying, `setSvgColor()` rasterizes the pressed-state arrow using `devicePixelRatioF()`, which can still reflect the old scale, so the arrow appears blurry while pressed.
Render the pressed-state arrow through the vector-based path instead of using the bitmap rasterized by `setSvgColor()`.
</issue_to_address>| // 原实现使用构造期按当时缩放比缓存的位图,分数倍缩放比在窗口创建后 | ||
| // 才被主题层异步应用,缓存位图被拉伸显示而模糊(PMS 171749)。 | ||
| // 注意:不可改用 devicePixelRatioF() 自行光栅化——分数缩放下该值不可靠。 | ||
| const QString arrowTheme = (dpalette.color(QPalette::Background).lightness() < 128) ? "dark" : "light"; |
There was a problem hiding this comment.
🟠 High · Arrows use the wrong theme color
When the editor theme differs from the button or application palette, createIcon() selects the SVG from the button palette, while BottomBar::setPalette() assigns the application palette to the buttons and supplies the editor theme separately to setTheme(). The normal-state arrow therefore uses the wrong light/dark asset and can lose contrast against the bottom bar.
Select the normal-state SVG from the theme supplied to setTheme() rather than from the button palette.
Also at src/widgets/ddropdownmenu.cpp:419.
Prompt for AI agents
In `src/widgets/ddropdownmenu.cpp` at line 418:
**Arrows use the wrong theme color**
When the editor theme differs from the button or application palette, `createIcon()` selects the SVG from the button palette, while `BottomBar::setPalette()` assigns the application palette to the buttons and supplies the editor theme separately to `setTheme()`. The normal-state arrow therefore uses the wrong light/dark asset and can lose contrast against the bottom bar.
Select the normal-state SVG from the theme supplied to `setTheme()` rather than from the button palette.
Also at `src/widgets/ddropdownmenu.cpp:419`.| if (m_bPressed) { | ||
| painter.drawPixmap(QRectF(fontWidth,(totalHeigth-iconH)/2,iconW,iconH),arrowPixmap,arrowPixmap.rect()); |
There was a problem hiding this comment.
🟡 Medium · Pressed arrows blur during scaling
When a dropdown is pressed before the fractional scale factor has finished applying, setSvgColor() rasterizes the pressed-state arrow using devicePixelRatioF(), which can still reflect the old scale, so the arrow appears blurry while pressed.
Render the pressed-state arrow through the vector-based path instead of using the bitmap rasterized by setSvgColor().
Prompt for AI agents
In `src/widgets/ddropdownmenu.cpp` at lines 411-412:
**Pressed arrows blur during scaling**
When a dropdown is pressed before the fractional scale factor has finished applying, `setSvgColor()` rasterizes the pressed-state arrow using `devicePixelRatioF()`, which can still reflect the old scale, so the arrow appears blurry while pressed.
Render the pressed-state arrow through the vector-based path instead of using the bitmap rasterized by `setSvgColor()`.456a818 to
385db03
Compare
…er fractional scaling - Rerender the bottom bar dropdown arrow from SVG on every icon rebuild instead of reusing the bitmap cached at widget construction, so the arrow always matches the density of the text rendered into the same icon pixmap 修复(editor): 下拉箭头改为矢量渲染,修复分数倍缩放下箭头模糊 - 底栏下拉菜单每次重建图标时,普通态箭头与按压态 setSvgColor 同源,按当前图标密度从 SVG 矢量渲染,不再沿用构造期按当时缩放比光栅化的缓存位图(分数倍缩放比由主题层在窗口创建后异步应用,缓存位图会被拉伸显示而模糊) Log: 修复分数倍缩放(如 1.5)下底栏下拉菜单箭头模糊的问题 Bug: https://pms.uniontech.com/bug-view-171749.html PMS: BUG-171749
385db03 to
e9ff8dc
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['清理 m_arrowPixmap 在构造函数和 setTheme() 中的赋值代码,以及头文件中的成员声明,避免死代码残留'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['将 QSvgRenderer 缓存为成员变量,仅在主题(arrowTheme)变化时重新创建,避免每次 createIcon() 重复解析 SVG', '移除构造函数和 setTheme() 中对 m_arrowPixmap 的无用赋值,消除浪费的 QSvgRenderer 创建和 QPixmap 渲染'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 建议将 QSvgRenderer 缓存为成员变量,避免重复解析
// 在头文件中添加:
// std::unique_ptr<QSvgRenderer> m_svgRenderer;
// QString m_lastArrowTheme;
// createIcon() 中的 else 分支改为:
} else {
// 箭头直接按当前图标密度矢量渲染,与文字密度保持一致。
const QString arrowTheme = (dpalette.color(QPalette::Background).lightness() < 128) ? "dark" : "light";
if (!m_svgRenderer || m_lastArrowTheme != arrowTheme) {
m_svgRenderer = std::make_unique<QSvgRenderer>(
QString(":/images/dropdown_arrow_%1.svg").arg(arrowTheme));
m_lastArrowTheme = arrowTheme;
}
m_svgRenderer->render(&painter, QRectF(fontWidth, (totalHeigth - iconH) / 2.0, iconW, iconH));
}
// 同时清理构造函数和 setTheme() 中对 m_arrowPixmap 的无用赋值本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, pppanghu77 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 |
|
/merge |
fix(editor): render dropdown arrows as vectors to keep them sharp under fractional scaling
Problem / 问题
Under fractional scaling (e.g. 1.5x), the three bottom bar dropdown arrows (UTF-8 / Unix / None) of the text editor look blurry: the scale factor is applied by the theme layer after window creation, while the arrows were rasterized into a bitmap cached at widget construction time (at 1x), and this cached bitmap keeps being reused afterwards. Text is unaffected because fonts follow the compensated DPI.
分数倍缩放(如 1.5)下,文本编辑器底栏三个下拉菜单的箭头模糊:缩放比由主题层在窗口创建之后异步应用,而箭头在控件构造期就按 1x 光栅化缓存(
m_arrowPixmap),后续一直沿用该缓存;文字因走字体 DPI 补偿不受影响,故症状表现为仅箭头模糊。Fix / 修复
In the normal (non-pressed) state of
DDropdownMenu::createIcon(), render the arrow SVG directly as a vector into the icon pixmap instead of reusing the construction-time cached bitmap — the arrow now always matches the density of the text rendered into the same pixmap, with no dependency ondevicePixelRatioF()(which is unreliable while the fractional factor is applied asynchronously)DDropdownMenu::createIcon()普通态箭头不再使用构造期缓存的位图,而是将箭头 SVG 矢量直接渲染进当前图标位图(与按压态setSvgColor同源思路),密度始终与同一图标内的文字一致;不依赖分数缩放比异步应用期间取值不可靠的devicePixelRatioF()Verified / 验证
3840x2160 screen at 1.5x scaling: all three arrows render sharp and consistent without any interaction
1x scaling: rendering pixel-identical to the unfixed build (no regression)
Typing and saving (Ctrl+S) work normally at 1.5x
Verified on a real 1.5x desktop (2560x1440 logical on a 4K panel)
3840x2160 屏 1.5x 缩放:三个箭头无需任何交互即清晰一致
1x 缩放:与未修复版本渲染逐像素一致(无回归)
1.5x 下键入与 Ctrl+S 保存功能正常
已在真实 1.5x 桌面(4K 屏逻辑 2560x1440)实测确认
Log: 修复分数倍缩放(如 1.5)下底栏下拉菜单箭头模糊的问题
Bug: https://pms.uniontech.com/bug-view-171749.html
Summary by Sourcery
Keep editor dropdown arrows sharp across fractional display scaling.
Bug Fixes:
Enhancements: