From 5ead8804239c984ef44ad73bb261f7517168f4ed Mon Sep 17 00:00:00 2001 From: zhangkun Date: Fri, 30 Jan 2026 17:05:58 +0800 Subject: [PATCH] fix: adjust scrollbar visibility based on system theme policy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed the scrollbar visibility initialization logic in ChameleonStyle to respect system theme's scrollbar policy. Previously, scrollbars were always set to visible by default, then hidden via animation. Now, when the system theme specifies Qt::ScrollBarAsNeeded policy, scrollbars start as invisible; otherwise, they remain visible by default. This ensures proper scrollbar behavior alignment with user's system preferences. fix: 根据系统主题策略调整滚动条可见性 修改了ChameleonStyle中滚动条可见性的初始化逻辑,以遵循系统主题的滚动条 策略。之前滚动条始终默认设置为可见,然后通过动画隐藏。现在,当系统主题指 定Qt::ScrollBarAsNeeded策略时,滚动条初始为不可见;其他情况下保持默认可 见。这确保了滚动条行为与用户系统偏好设置的一致性。 PMS: BUG-339051 --- styleplugins/chameleon/chameleonstyle.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index b9bc3939..8813797b 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -901,12 +901,12 @@ bool ChameleonStyle::hideScrollBarByAnimation(const QStyleOptionSlider *scrollBa bool isHoveredOrPressed = hoveredOrPressed(scrollBar) || sbar->underMouse(); if (isHoveredOrPressed && st == QAbstractAnimation::Running) { // 标记一下,鼠标移开时需要重新开启隐藏动画 - sbar->setProperty("_d_dtk_scrollbar_visible", true); + sbar->setProperty("_d_dtk_scrollbar_hide_ani", true); return false; } - if (sbar->property("_d_dtk_scrollbar_visible").toBool()) { - sbar->setProperty("_d_dtk_scrollbar_visible", false); + if (sbar->property("_d_dtk_scrollbar_hide_ani").toBool()) { + sbar->setProperty("_d_dtk_scrollbar_hide_ani", false); styleAnimation->restart(true); return false; } @@ -4623,8 +4623,8 @@ void ChameleonStyle::resetAttribute(QWidget *w, bool polish) w->setAttribute(Qt::WA_Hover, enableHover); if (auto scrollbar = qobject_cast(w)) { - // 默认初始显示滚动条,然后启动隐藏动画 - scrollbar->setProperty("_d_dtk_scrollbar_visible", true); + // 默认情况下不执行隐藏动画 + scrollbar->setProperty("_d_dtk_scrollbar_hide_ani", false); scrollbar->setAttribute(Qt::WA_OpaquePaintEvent, !polish); } }