fix: scrollbar transparent in dark mode - #405
deepin-bot[bot] merged 1 commit into
Conversation
Reviewer's GuideThe PR fixes nearly invisible dark-mode scrollbar handles by explicitly setting both scrollbars’ Base palette to white, synchronizing their palettes and the view background on theme changes, and ensuring the handles remain visible without relying on ineffective active-state styling. Sequence diagram for theme-aware scrollbar palette synchronizationsequenceDiagram
participant Theme as DGuiApplicationHelper
participant Sheet as SheetBrowser
participant Vertical as VerticalScrollBar
participant Horizontal as HorizontalScrollBar
participant Style as ChameleonStyle
Sheet->>Theme: themeTypeChanged
Theme-->>Sheet: onUpdateTheme()
Sheet->>Sheet: setPalette(plt)
Sheet->>Sheet: setBackgroundBrush(plt.itemBackground().color())
Sheet->>Vertical: setPalette(Base=white)
Sheet->>Horizontal: setPalette(Base=white)
Style->>Vertical: drawControl(CE_ScrollBarSlider)
Style->>Horizontal: drawControl(CE_ScrollBarSlider)
Style-->>Vertical: draw dark scrollbar handle
Style-->>Horizontal: draw dark scrollbar handle
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
eafca0b to
ef6fb67
Compare
…rollbar palette 1. 移除无效的 ScrollBarActiveStyle(强加 State_Active 不影响 ChameleonStyle 的滑块取色逻辑); 2. 主题更新时强制两个滚动条的 QPalette::Base 为浅色,使滑块恒为深色; 3. 恢复 WA_TranslucentBackground,保持文档视图原有背景行为; 4. 保留 themeTypeChanged 同步,主题切换时重新应用滚动条调色板与视图背景; ===================================== 1. removed the ineffective ScrollBarActiveStyle (forcing State_Active does not affect ChameleonStyle's handle color logic); 2. forced QPalette::Base of both scrollbars to a light color on theme update so the handle is always drawn dark; 3. restored WA_TranslucentBackground to keep the original view background behavior; 4. kept the themeTypeChanged sync to re-apply scrollbar palette and view background on theme switch; Log: 修复深色模式下文档查看器滚动条透明不可见的问题,放大文档后滚动条清晰可辨 PMS: BUG-374553
8d1de6c to
9962505
Compare
|
经用户最终复测确认:合并方案(本 PR)之前的代码状态(release/eagle @ 17d7b5f)滚动条显示正常,本 PR 的改动(删除 WA_TranslucentBackground + 添加 _d_dtk_slider_always_show / ScrollBarAlwaysOn / onUpdateTheme())反而引入了回归(滚动条不清晰)。 根因分析修正:原始分析将 WA_TranslucentBackground 误判为根因,实际该属性在当前基线下并未导致滚动条透明问题。PR 的修改引入了 onUpdateTheme() 中强制 palette(Base)=white 等不当改动,导致滚动条显示异常。 处理方式:关闭本 PR,回退至合并前基线状态。无需代码改动。 |
9962505 to
8d1de6c
Compare
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="reader/browser/SheetBrowser.cpp" line_range="99" />
<code_context>
+ // 阻止 DTK ChameleonStyle 的 hideScrollBarByAnimation() 自动隐藏滑块
+ this->verticalScrollBar()->setProperty("_d_dtk_slider_always_show", true);
+ this->horizontalScrollBar()->setProperty("_d_dtk_slider_always_show", true);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+
+ connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SheetBrowser::onUpdateTheme);
</code_context>
<issue_to_address>
**nitpick (broader_impact):** `Qt::ScrollBarAlwaysOn` reserves vertical scrollbar space and displays an empty vertical scrollbar even when the document has no vertical overflow. This permanently reduces the document viewport and can also create a horizontal scrollbar for pages whose width previously fit exactly.
**Triggers:** When a document fits vertically, especially when its width is close to the available viewport width.
**Suggested fix:** Keep the vertical policy as `Qt::ScrollBarAsNeeded` and rely on a verified DTK always-show mechanism, or enable `AlwaysOn` only while vertical scrolling is actually required.
```suggestion
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
```
</issue_to_address>| // 阻止 DTK ChameleonStyle 的 hideScrollBarByAnimation() 自动隐藏滑块 | ||
| this->verticalScrollBar()->setProperty("_d_dtk_slider_always_show", true); | ||
| this->horizontalScrollBar()->setProperty("_d_dtk_slider_always_show", true); | ||
| setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); |
There was a problem hiding this comment.
nitpick (broader_impact): Qt::ScrollBarAlwaysOn reserves vertical scrollbar space and displays an empty vertical scrollbar even when the document has no vertical overflow. This permanently reduces the document viewport and can also create a horizontal scrollbar for pages whose width previously fit exactly.
Triggers: When a document fits vertically, especially when its width is close to the available viewport width.
Suggested fix: Keep the vertical policy as Qt::ScrollBarAsNeeded and rely on a verified DTK always-show mechanism, or enable AlwaysOn only while vertical scrolling is actually required.
| setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); | |
| setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码语法正确,逻辑清晰,无需修改 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 代码结构清晰,注释完整,无需修改 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理,无需优化 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 安全合规,无需加固 💡 改进建议代码示例// 暂无代码示例 - 代码质量优秀,无需修复本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: max-lvs, Resurgamz 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 |
根因分析 / Root Cause
SheetBrowser继承DGraphicsView(实为typedef QGraphicsView),其滚动条是普通QScrollBar,由 DTK 的 ChameleonStyle 绘制。ChameleonStyle::drawControl(CE_ScrollBarSlider)依据滚动条QPalette::Base的明暗决定滑块颜色:深色模式下
QPalette::Base为深色,ChameleonStyle 因此绘制白色半透明滑块;而文档页面恒为白色,滑块在白色页面上几乎不可见(测试描述为“透明色”)。WA_TranslucentBackground使滚动条 groove 透出底层,进一步降低对比度。关键证据:
dde-qt5integration5.6.16styleplugins/chameleon/chameleonstyle.cpp中CE_ScrollBarSlider的取色逻辑仅依赖palette(Base),与State_Active无关——因此强加State_Active的QProxyStyle方案无效。SheetBrowserextendsDGraphicsView(atypedefofQGraphicsView); its scrollbars are plainQScrollBarpainted by DTK ChameleonStyle. The handle color is chosen from the scrollbar'sQPalette::Base: a dark Base (dark mode) makes ChameleonStyle draw a translucent white handle, which is nearly invisible on the always-white document page.修复方案 / Fix
在主题更新时强制两个滚动条的
QPalette::Base为浅色,使 ChameleonStyle 始终绘制深色滑块;同时保留themeTypeChanged同步,主题切换时重新应用滚动条调色板与视图背景。移除此前的ScrollBarActiveStyle(强加State_Active不影响滑块取色逻辑,已确认无效),并恢复WA_TranslucentBackground保持视图原有背景行为。Force
QPalette::Baseof both scrollbars to a light color on theme update so ChameleonStyle always draws a dark handle; keep thethemeTypeChangedsync to re-apply the scrollbar palette and view background. The previousScrollBarActiveStyle(forcingState_Active) is removed since it does not affect the handle color logic.WA_TranslucentBackgroundis restored to keep the original view background behavior.改动安全评估 / Change Safety
WA_TranslucentBackground恢复为原状。WA_TranslucentBackgroundis restored.验证建议 / Verification
Summary by Sourcery
Make document viewer scrollbars remain visible and readable across light and dark theme changes.
Bug Fixes:
Enhancements: