Skip to content

Commit 0d767ca

Browse files
committed
fix(slider): optimize tick label alignment to prevent text overflow
Add isFirst/isLast properties and effectiveHorizontalAlignment to align first/last tick labels outward (left for first, right for last), preventing text overflow at slider edges. Use negative margins to offset label padding for better visual alignment with tick marks. Add null safety checks and documentation comments. 为 SliderTipItem 添加首尾刻度标签特殊对齐逻辑,首刻度左对齐、尾刻度右对齐, 防止文本在滑块边缘溢出。使用负边距抵消标签 padding,使文字与刻度对齐。 添加空值安全检查和文档注释。 Log: 优化滑块刻度标签对齐,防止边缘文本溢出 PMS: BUG-305223 Influence: TipsSlider 的首尾刻度标签现在会自动向外对齐,提升视觉效果并防止文本溢出。
1 parent 4de6f3c commit 0d767ca

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

qt6/src/qml/SliderTipItem.qml

Lines changed: 24 additions & 9 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

@@ -14,6 +14,21 @@ Control {
1414
readonly property int direction: parent.parent.tickDirection
1515
readonly property bool horizontal: parent.parent.children[0].horizontal
1616
property bool highlight
17+
readonly property bool isFirst: {
18+
var ticks = parent.parent.ticks || []
19+
return ticks.indexOf(control) === 0
20+
}
21+
readonly property bool isLast: {
22+
var ticks = parent.parent.ticks || []
23+
return ticks.indexOf(control) === ticks.length - 1
24+
}
25+
// Align first/last tick labels outward to prevent text overflow at slider edges
26+
readonly property int effectiveHorizontalAlignment: {
27+
if (!horizontal) return textHorizontalAlignment
28+
if (isFirst) return Text.AlignLeft
29+
if (isLast) return Text.AlignRight
30+
return textHorizontalAlignment
31+
}
1732

1833
property D.Palette tickColor: DS.Style.slider.tick.background
1934
property D.Palette textColor: highlight ? DS.Style.checkedButton.text: DS.Style.button.text
@@ -36,16 +51,16 @@ Control {
3651
active: text.length !== 0
3752
anchors {
3853
top: horizontal ? (TipsSlider.TickDirection.Back === direction ? __rect.bottom : undefined) : undefined
39-
topMargin: horizontal && (TipsSlider.TickDirection.Back === direction) ? DS.Style.slider.tick.vPadding : undefined
54+
topMargin: horizontal && (TipsSlider.TickDirection.Back === direction) ? DS.Style.slider.tick.vPadding : -DS.Style.slider.tick.vPadding
4055
bottom: horizontal ? (TipsSlider.TickDirection.Front === direction ? __rect.top : undefined) : undefined
41-
bottomMargin: horizontal && (TipsSlider.TickDirection.Front === direction) ? DS.Style.slider.tick.vPadding : undefined
42-
left: horizontal ? (Text.AlignLeft === textHorizontalAlignment ? __rect.left : undefined)
56+
bottomMargin: horizontal && (TipsSlider.TickDirection.Front === direction) ? DS.Style.slider.tick.vPadding : -DS.Style.slider.tick.vPadding
57+
left: horizontal ? (Text.AlignLeft === effectiveHorizontalAlignment ? __rect.left : undefined)
4358
: (TipsSlider.TickDirection.Back === direction ? __rect.right : undefined)
44-
leftMargin: !horizontal && TipsSlider.TickDirection.Back === direction ? DS.Style.slider.tick.hPadding : undefined
45-
right: horizontal ? (Text.AlignRight === textHorizontalAlignment ? __rect.right : undefined)
59+
leftMargin: !horizontal && TipsSlider.TickDirection.Back === direction ? DS.Style.slider.tick.hPadding : -DS.Style.slider.tick.hPadding
60+
right: horizontal ? (Text.AlignRight === effectiveHorizontalAlignment ? __rect.right : undefined)
4661
: (TipsSlider.TickDirection.Front === direction ? __rect.left : undefined)
47-
rightMargin: !horizontal && TipsSlider.TickDirection.Front === direction ? DS.Style.slider.tick.hPadding : undefined
48-
horizontalCenter: horizontal && Text.AlignHCenter === textHorizontalAlignment ? __rect.horizontalCenter : undefined
62+
rightMargin: !horizontal && TipsSlider.TickDirection.Front === direction ? DS.Style.slider.tick.hPadding : -DS.Style.slider.tick.hPadding
63+
horizontalCenter: horizontal && Text.AlignHCenter === effectiveHorizontalAlignment ? __rect.horizontalCenter : undefined
4964
verticalCenter: horizontal ? undefined : __rect.verticalCenter
5065
}
5166

@@ -55,7 +70,7 @@ Control {
5570
leftPadding: rightPadding
5671
topPadding: highlight ? DS.Style.slider.tick.vPadding : 0
5772
bottomPadding: topPadding
58-
horizontalAlignment: textHorizontalAlignment
73+
horizontalAlignment: control.effectiveHorizontalAlignment
5974
verticalAlignment: Text.AlignVCenter
6075
palette.windowText: control.D.ColorSelector.textColor
6176
background: Loader {

0 commit comments

Comments
 (0)