Skip to content

Commit a55b6ee

Browse files
add-uos18202781743
authored andcommitted
feat(slider): add tick alignment support for Slider component
Add alignToTicks property to Slider, allowing the groove to align with tick marks when enabled. The groove drawing is offset by half the handle width on both ends when alignToTicks is true. 为 Slider 组件添加 alignToTicks 属性,支持滑块槽与刻度标记对齐。 启用时,槽的绘制会在两端偏移半个手柄宽度。 Log: 添加 Slider 刻度对齐功能 PMS: BUG-275271 Influence: 当 TipsSlider 有刻度时,滑块槽会自动与刻度对齐,提升视觉效果。
1 parent c785814 commit a55b6ee

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ui_*.h
2626
*.qmlc
2727
*.jsc
2828
Makefile*
29-
*build-*
29+
build*
3030
src/translations/*.qm
3131

3232
# Qt unit tests

qt6/src/qml/Slider.qml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -26,6 +26,7 @@ T.Slider {
2626
property real dashOffset: 0.0
2727
property var dashPattern: [0.5, 0.25]
2828
property bool highlightedPassedGroove: false
29+
property bool alignToTicks: false
2930

3031
implicitWidth: Math.max(background ? background.implicitWidth : 0,
3132
(handle ? handle.implicitWidth : 0) + leftPadding + rightPadding)
@@ -76,10 +77,10 @@ T.Slider {
7677
strokeWidth: control.horizontal ? sliderGroove.height : sliderGroove.width
7778
dashOffset: control.dashOffset
7879
dashPattern: control.dashPattern
79-
startX: control.horizontal ? 0 : sliderGroove.width / 2
80+
startX: control.horizontal ? (control.alignToTicks ? __handle.width / 2 : 0) : sliderGroove.width / 2
8081
startY: control.horizontal ? sliderGroove.height / 2 : 0
8182
PathLine {
82-
x: control.horizontal ? sliderGroove.width : sliderGroove.width / 2
83+
x: control.horizontal ? (control.alignToTicks ? sliderGroove.width - __handle.width / 2 : sliderGroove.width) : sliderGroove.width / 2
8384
y: control.horizontal ? sliderGroove.height / 2 : sliderGroove.height
8485
}
8586
}
@@ -96,7 +97,7 @@ T.Slider {
9697
strokeWidth: control.horizontal ? sliderGroove.height : sliderGroove.width
9798
dashOffset: control.dashOffset
9899
dashPattern: control.dashPattern
99-
startX: control.horizontal ? 0 : sliderGroove.width / 2
100+
startX: control.horizontal ? (control.alignToTicks ? __handle.width / 2 : 0) : sliderGroove.width / 2
100101
startY: control.horizontal ? sliderGroove.height / 2 : sliderGroove.height
101102
PathLine {
102103
x: control.horizontal ? control.handle.x : sliderGroove.width / 2

qt6/src/qml/TipsSlider.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -21,6 +21,7 @@ Control {
2121

2222
Slider {
2323
id: __slider
24+
alignToTicks: ticks.length > 0
2425
anchors {
2526
left: horizontal ? parent.left : (TipsSlider.TickDirection.Back === tickDirection ? parent.left : undefined)
2627
right: horizontal ? parent.right : (TipsSlider.TickDirection.Front === tickDirection ? parent.right : undefined)

0 commit comments

Comments
 (0)