Skip to content

fix: restore edit palette text color under Qt6 - #742

Closed
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383315
Closed

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/bugfix/383315

Conversation

@add-uos

@add-uos add-uos commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

Under Qt6, setEditPalette() in src/editor/dtextedit.cpp:5958 was made a no-op by commit 65bc75a3 (BUG-305473), which assumed DTK6 would auto-manage the palette. In practice, DTK6 does not set QPalette::Text for QPlainTextEdit, leaving the text color identical to the background (e.g., white-on-white), making editor text invisible. The minimal reproduction demo quantified this: no-op path contrast ratio 1.048:1 (text invisible) vs. fixed path 6.278:1 (text visible).

Additionally, slotLoadContentTheme() (window.cpp:4040) passed the system palette text color instead of the theme file's text color, and the manual theme selection path (OnThemeChangeSlot) lacked a setEditPalette() call entirely.

Fix

  1. Removed the #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) no-op branch in setEditPalette(), restoring setPalette() execution on all Qt versions.
  2. Changed slotLoadContentTheme() to use the theme file's text-color (via Utils::getThemeMapFromPath) instead of the system palette text color.
  3. Added setEditPalette(textColor, textColor) call in OnThemeChangeSlot() to cover the manual theme selection path.

Change Safety Assessment

Code Safety

  • Risk Level: Medium
  • Partially reverts commit 65bc75a3 (BUG-305473); original issue won't recur because both system theme switch and manual theme selection paths now source text color from theme JSON and call setEditPalette().
  • All three call sites verified compatible: constructor (dtextedit.cpp:105), system theme switch (window.cpp:4043), manual theme selection (editwrapper.cpp:1311).

Business Impact Scope

  • Editor theme switching: text color correctly updates on system dark/light theme switch and manual theme panel selection.
  • New editor windows: initial text color set correctly at construction.
  • Affected modules: text editor rendering, theme management.

Verification Suggestion

  • Test text visibility after system dark↔light theme switch.
  • Test text visibility after manual theme selection from the theme panel.
  • Verify syntax highlight colors still render correctly.

根因分析

Qt6 下 setEditPalette()(src/editor/dtextedit.cpp:5958)被 commit 65bc75a3(BUG-305473)改为空操作,假设 DTK6 会自动管理调色板。实际 DTK6 不会为 QPlainTextEdit 设置 QPalette::Text,导致文本色与背景色相同(如白底白字),编辑器文本不可见。最小复现 demo 量化验证:空操作路径对比度 1.048:1(文本不可见)vs 修复路径 6.278:1(文本可见)。

此外,slotLoadContentTheme()(window.cpp:4040)传入系统调色板文本色而非主题文件文本色,手动选主题路径(OnThemeChangeSlot)完全缺失 setEditPalette() 调用。

修复方案

  1. 移除 setEditPalette() 中 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 空操作分支,恢复 Qt6 下 setPalette() 执行。
  2. slotLoadContentTheme() 改用主题文件的 text-color(经 Utils::getThemeMapFromPath)而非系统调色板文本色。
  3. 在 OnThemeChangeSlot() 补充 setEditPalette(textColor, textColor) 调用,覆盖手动选主题路径。

改动安全评估

代码安全评估

  • 风险等级: 中风险
  • 部分撤销 commit 65bc75a3(BUG-305473);原问题不会复发,因为系统主题切换和手动选主题两条路径均从主题 JSON 取色并调用 setEditPalette()。
  • 三处调用点均验证兼容:构造器(dtextedit.cpp:105)、系统主题切换(window.cpp:4043)、手动选主题(editwrapper.cpp:1311)。

业务影响范围

  • 编辑器主题切换:系统深/浅主题切换和手动从主题面板选择主题后,编辑区文本颜色正确更新。
  • 新建编辑器窗口:构造时初始文本色正确设置。
  • 受影响模块:文本编辑器渲染、主题管理。

验证建议

  • 测试系统深色↔浅色主题切换后编辑区文本可见。
  • 测试从主题面板手动选择主题后编辑区文本可见。
  • 验证语法高亮颜色渲染正常。

Summary by Sourcery

Restore theme-aware editor text palette handling so text remains readable across Qt6 theme changes.

Bug Fixes:

  • Restore visible editor text colors under Qt6 during initial setup and system or manual theme changes by applying the theme-defined text color.

Enhancements:

  • Ensure editor palette updates consistently across all supported Qt versions and theme-selection paths.

@add-uos
add-uos marked this pull request as draft November 20, 2026 17:01
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Update system and manually selected theme paths to read the normal text color from the correct theme JSON key and apply it to the editor palette.

  • src/editor/editwrapper.cpp L1279, L1311
  • src/widgets/window.cpp L4039-4040

Implementation

Restore palette text-color application in setEditPalette() on Qt 6 as well as earlier Qt versions.

  • src/editor/dtextedit.cpp L5961-5962, L5967 (removed lines)

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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/widgets/window.cpp" line_range="4039-4040" />
<code_context>
     }

-    QString qstrColor = palette().color(QPalette::Active, QPalette::Text).name();
+    QVariantMap themeMap = Utils::getThemeMapFromPath(m_themePath);
+    QString qstrColor = themeMap["Normal"].toMap()["text-color"].toString();

     for (auto wrapper : m_wrappers) {
</code_context>
<issue_to_address>
**Editor text color is not applied**

When a shipped theme uses the `text-styles.Normal.text-color` schema, the lookups in `Window::slotLoadContentTheme()` and `EditWrapper::OnThemeChangeSlot()` read `Normal` at the map root, return an empty color, and pass it to `setEditPalette()`, so the editor keeps an incorrect or default color and can become unreadable against the theme background.

Read `text-styles.Normal.text-color` in both theme-change paths.

Also at `src/editor/editwrapper.cpp:1311`.
</issue_to_address>

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

Comment thread src/widgets/window.cpp Resolved
@add-uos
add-uos force-pushed the agent/bugfix/383315 branch from 3956189 to 941fa6e Compare November 20, 2026 17:12
@add-uos
add-uos marked this pull request as ready for review November 24, 2026 03:33
1. Root cause: setEditPalette() was made a no-op under Qt6 by
   commit 65bc75a (BUG-305473), assuming DTK6 auto-manages palette;
   DTK6 does not set QPlainTextEdit text color, making text invisible.
   Additionally, text color was extracted via wrong JSON key path
   (top-level "Normal" instead of "text-styles"."Normal"), returning
   empty string and making setEditPalette receive invalid QColor("")
2. Fix: remove the Qt6 no-op branch so setPalette() executes on all
   Qt versions; use correct key path themeMap["text-styles"]["Normal"]
   ["text-color"] in both slotLoadContentTheme and OnThemeChangeSlot;
   add setEditPalette() call in OnThemeChangeSlot to cover manual
   theme selection path
3. Impact: text color now correctly follows theme on both system
   theme switch and manual theme panel selection

Log: fix invisible text in editor under Qt6 theme switch

Influence:
1. Test text visibility after system dark/light theme switch
2. Test text visibility after manual theme selection from panel
3. Verify syntax highlight colors still render correctly

fix: 修复 Qt6 下编辑器文本色不可见问题

1. 根因:commit 65bc75a(BUG-305473)将 setEditPalette() 在 Qt6 下
   改为空操作,假设 DTK6 自动管理调色板;但 DTK6 不会设置
   QPlainTextEdit 文本色,导致文本与背景同色不可见。同时文本色
   通过错误的 JSON 键路径(顶级 "Normal" 而非 "text-styles"."Normal")
   获取,返回空字符串使 setEditPalette 收到无效 QColor("")
2. 方案:移除 Qt6 空操作分支使 setPalette() 在所有 Qt 版本执行;
   slotLoadContentTheme 和 OnThemeChangeSlot 均改用正确键路径
   themeMap["text-styles"]["Normal"]["text-color"] 获取文本色;
   OnThemeChangeSlot 补充 setEditPalette 调用覆盖手动选主题路径
3. 影响:系统主题切换和手动选择主题后文本色均正确更新

Influence:
1. 测试系统深色/浅色主题切换后编辑区文本可见
2. 测试从主题面板手动选择主题后编辑区文本可见
3. 验证语法高亮颜色渲染正常

PMS: BUG-383315
Log: 修复 Qt6 下主题切换后编辑器文本不可见问题
@add-uos
add-uos force-pushed the agent/bugfix/383315 branch from 941fa6e to 9308882 Compare November 24, 2026 03:38
@add-uos add-uos closed this Nov 24, 2026
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.

2 participants