Skip to content

fix(editor): render dropdown arrows as vectors to keep them sharp under fractional scaling - #734

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:verify/ws4199-highdpi
Nov 17, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
pppanghu77:verify/ws4199-highdpi

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 on devicePixelRatioF() (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:

  • Fix blurry editor dropdown arrows when fractional display scaling is applied.

Enhancements:

  • Render normal-state dropdown arrows as vectors at the current icon density while preserving existing pressed-state behavior and 1x rendering.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Review 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.

  • src/widgets/ddropdownmenu.cpp L1, L375 (removed lines), L411-421

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

// 原实现使用构造期按当时缩放比缓存的位图,分数倍缩放比在窗口创建后
// 才被主题层异步应用,缓存位图被拉伸显示而模糊(PMS 171749)。
// 注意:不可改用 devicePixelRatioF() 自行光栅化——分数缩放下该值不可靠。
const QString arrowTheme = (dpalette.color(QPalette::Background).lightness() < 128) ? "dark" : "light";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 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`.

Comment thread src/widgets/bottombar.cpp Resolved
Comment thread src/widgets/bottombar.cpp Resolved
Comment on lines +411 to +412
if (m_bPressed) {
painter.drawPixmap(QRectF(fontWidth,(totalHeigth-iconH)/2,iconW,iconH),arrowPixmap,arrowPixmap.rect());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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()`.

@pppanghu77
pppanghu77 force-pushed the verify/ws4199-highdpi branch 2 times, most recently from 456a818 to 385db03 Compare November 17, 2026 07:50
…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
@pppanghu77
pppanghu77 force-pushed the verify/ws4199-highdpi branch from 385db03 to e9ff8dc Compare November 17, 2026 11:12
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 95 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将下拉箭头从缓存位图渲染改为 SVG 矢量渲染,修复了分数倍缩放下箭头模糊的问题(PMS 171749)。 语法逻辑正确,注释详尽;代码质量方面存在 m_arrowPixmap 成为死代码的遗留问题;性能方面 QSvgRenderer 每次 createIcon() 调用均重新构造解析 SVG,存在轻微优化空间;代码安全无漏洞。总体质量良好。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['清理 m_arrowPixmap 在构造函数和 setTheme() 中的赋值代码,以及头文件中的成员声明,避免死代码残留']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 QSvgRenderer 缓存为成员变量,仅在主题(arrowTheme)变化时重新创建,避免每次 createIcon() 重复解析 SVG', '移除构造函数和 setTheme() 中对 m_arrowPixmap 的无用赋值,消除浪费的 QSvgRenderer 创建和 QPixmap 渲染']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 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 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[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.

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

@pppanghu77

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit e859403 into linuxdeepin:release/eagle Nov 17, 2026
20 checks passed
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