From 260603c18a57d95d3cb63d5f3de0527008bf2285 Mon Sep 17 00:00:00 2001 From: zqq-dora Date: Thu, 19 Nov 2026 15:32:45 +0800 Subject: [PATCH] fix(scrollbar): refine width, radius, opacity for per-state styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor ScrollBar to distinguish vertical and horizontal widths, fix opacity values, and use dedicated radius tokens instead of dynamic height/2 or width/2. Style tokens (qt6/src/qml/FlowStyle.qml): - Vertical width 4 -> 6; add horizontalWidth: 4 for slimmer horizontal bars - Add hoverWidth: 14 and horizontalHoverWidth: 12 for orientation-aware hover sizing (previously both used activeWidth: 12) - Add normalRadius: 4 (hide/normal) and radius: 6 (hover/pressed), replacing dynamic height/2 or width/2 - Background opacity: normal 0.3 -> 0.5, hovered 0.4 -> 0.7; hoveredDark 0.6 -> 0.7 - insideBorder: normalDark 0.1 -> 0.05; add hoveredDark (0.1) and pressedDark (0.05) Control (qt6/src/qml/ScrollBar.qml): - hide / normal / hover states use orientation-aware width tokens - pressed (active) state keeps activeWidth: 12; with 1px border on each side the visual width is 14, matching hover - All four states now drive backgroundRect.radius: normalRadius (4) for hide/normal, radius (6) for hover/pressed, replacing the old dynamic height/2 / width/2 - contentItem.implicitWidth default is orientation-aware Exhibition demo (examples/exhibition/ScrollBar.qml): - Add theme-aware border and content background colors via ApplicationHelper.n so scrollbars are visible in both light and dark modes - Fix "D is not defined" ReferenceError by replacing D.DTK.themeType / D.ApplicationHelper with correct unqualified QML references 重构 ScrollBar 样式,区分垂直和水平方向宽度,修正透明度,并使用独立的 圆角参数替代动态的 height/2 / width/2。 样式参数 (qt6/src/qml/FlowStyle.qml): - 垂直宽度 4 -> 6;新增 horizontalWidth: 4,水平滚动条保持纤细 - 新增 hoverWidth: 14 和 horizontalHoverWidth: 12,区分方向的 hover 宽度 (之前统一用 activeWidth: 12) - 新增 normalRadius: 4(隐藏/正常态)和 radius: 6(hover/pressed 态), 取代动态的 height/2 / width/2 - 背景透明度:normal 0.3 -> 0.5,hover 0.4 -> 0.7;hoveredDark 0.6 -> 0.7 - insideBorder:normalDark 0.1 -> 0.05;新增 hoveredDark (0.1) 和 pressedDark (0.05) 控件 (qt6/src/qml/ScrollBar.qml): - 隐藏 / 正常 / hover 状态使用方向感知的宽度参数 - pressed(active)状态保持 activeWidth: 12;加上两侧各 1px 外描边, 视觉宽度为 14,与 hover 一致 - 四个状态均驱动 backgroundRect.radius:隐藏/正常用 normalRadius (4), hover/pressed 用 radius (6),取代旧的动态 height/2 / width/2 - contentItem.implicitWidth 默认值改为方向感知 Exhibition 示例 (examples/exhibition/ScrollBar.qml): - 通过 ApplicationHelper.n 添加主题感知的边框色和内容背景色,浅色和深色 模式下都能清楚看到滚动条 - 修复 D is not defined 的 ReferenceError,将 D.DTK.themeType / D.ApplicationHelper 替换为正确的无前缀 QML 引用 --- examples/exhibition/ScrollBar.qml | 15 +++++++++++---- qt6/src/qml/FlowStyle.qml | 18 +++++++++++++----- qt6/src/qml/ScrollBar.qml | 28 ++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/examples/exhibition/ScrollBar.qml b/examples/exhibition/ScrollBar.qml index 2d8e5ad2d..a5add7f8f 100644 --- a/examples/exhibition/ScrollBar.qml +++ b/examples/exhibition/ScrollBar.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -7,6 +7,11 @@ import org.deepin.dtk 1.0 Column { id: panel + + property bool darkMode: ApplicationHelper.n === ApplicationHelper.DarkType + property color borderColor: darkMode ? "#3d3d3d" : "#cacaca" + property color contentBgColor: darkMode ? "#2a2a2a" : "#f5f5f5" + Label { width: parent.width wrapMode: Text.WordWrap @@ -21,7 +26,8 @@ Column { width: parent.width Rectangle { - border.color: "#cacaca" + border.color: panel.borderColor + color: panel.contentBgColor width: 300 height: 213 Flickable { @@ -44,14 +50,15 @@ Column { } } - Item { width: parent.width; height: 1} + Item { width: parent.width; height: 1 } Rectangle { id: frame clip: true width: 1000 height: 278 - border.color: "black" + border.color: panel.borderColor + color: panel.contentBgColor Rectangle { id: content width: 450 diff --git a/qt6/src/qml/FlowStyle.qml b/qt6/src/qml/FlowStyle.qml index 7c089f110..7fb0d3242 100644 --- a/qt6/src/qml/FlowStyle.qml +++ b/qt6/src/qml/FlowStyle.qml @@ -852,19 +852,24 @@ QtObject { // Bar property QtObject scrollBar: QtObject { property int padding: 2 - property int width: 4 + property int width: 6 + property int horizontalWidth: 4 property int activeWidth: 12 + property int hoverWidth: 14 + property int horizontalHoverWidth: 12 + property int normalRadius: 4 property real hideOpacity: 0.0 property int hidePauseDuration: 450 property int hideDuration: 1500 property int hideWidthDuration: 100 + property int radius: 6 property D.Palette background: D.Palette { - normal: Qt.rgba(0, 0, 0, 0.3) + normal: Qt.rgba(0, 0, 0, 0.5) normalDark: Qt.rgba(1, 1, 1, 0.3) - hovered: Qt.rgba(0, 0, 0, 0.4) - hoveredDark: Qt.rgba(1, 1, 1, 0.6) + hovered: Qt.rgba(0, 0, 0, 0.7) + hoveredDark: Qt.rgba(1, 1, 1, 0.7) pressed: Qt.rgba(0, 0, 0, 0.4) pressedDark: Qt.rgba(1, 1, 1, 0.3) @@ -877,7 +882,10 @@ QtObject { property D.Palette insideBorder: D.Palette { normal: Qt.rgba(0, 0, 0, 0.05) - normalDark: Qt.rgba(1, 1, 1, 0.1) + normalDark: Qt.rgba(1, 1, 1, 0.05) + + hoveredDark: Qt.rgba(1, 1, 1, 0.1) + pressedDark: Qt.rgba(1, 1, 1, 0.05) } } diff --git a/qt6/src/qml/ScrollBar.qml b/qt6/src/qml/ScrollBar.qml index 13d4ee184..a9afcb800 100644 --- a/qt6/src/qml/ScrollBar.qml +++ b/qt6/src/qml/ScrollBar.qml @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -55,16 +55,24 @@ T.ScrollBar { when: __currentState === 0 PropertyChanges { target: control.contentItem - implicitWidth: DS.Style.scrollBar.width + implicitWidth: control.orientation == Qt.Horizontal ? DS.Style.scrollBar.horizontalWidth : DS.Style.scrollBar.width opacity: DS.Style.scrollBar.hideOpacity } + PropertyChanges { + target: backgroundRect + radius: DS.Style.scrollBar.normalRadius + } }, State { name: "normal" when: __currentState === 1 PropertyChanges { target: control.contentItem - implicitWidth: DS.Style.scrollBar.width + implicitWidth: control.orientation == Qt.Horizontal ? DS.Style.scrollBar.horizontalWidth : DS.Style.scrollBar.width + } + PropertyChanges { + target: backgroundRect + radius: DS.Style.scrollBar.normalRadius } }, State { @@ -72,7 +80,11 @@ T.ScrollBar { when: __currentState === 2 PropertyChanges { target: control.contentItem - implicitWidth: DS.Style.scrollBar.activeWidth + implicitWidth: control.orientation == Qt.Horizontal ? DS.Style.scrollBar.horizontalHoverWidth : DS.Style.scrollBar.hoverWidth + } + PropertyChanges { + target: backgroundRect + radius: DS.Style.scrollBar.radius } }, State { @@ -82,6 +94,10 @@ T.ScrollBar { target: control.contentItem implicitWidth: DS.Style.scrollBar.activeWidth } + PropertyChanges { + target: backgroundRect + radius: DS.Style.scrollBar.radius + } } ] @@ -100,13 +116,13 @@ T.ScrollBar { property D.Palette insideBorderColor: DS.Style.scrollBar.insideBorder property D.Palette outsideBorderColor: DS.Style.scrollBar.outsideBorder - implicitWidth: DS.Style.scrollBar.width + implicitWidth: control.orientation == Qt.Horizontal ? DS.Style.scrollBar.horizontalWidth : DS.Style.scrollBar.width implicitHeight: implicitWidth Rectangle { id: backgroundRect anchors.fill: parent - radius: control.orientation == Qt.Horizontal ? control.height / 2 : control.width / 2 + radius: DS.Style.scrollBar.normalRadius color: content.D.ColorSelector.backgroundColor }