Skip to content

Commit 42fd9ed

Browse files
committed
fix(ComboBox): fix highlight lingering after mouse leaves
- Track the popup's hover state by adding a isInteractingWithContent property to ComboBox, and modify the highlighted property in the delegate. - The logic of the highlighted property now depends on isInteractingWithContent, automatically clearing the highlight when the mouse leaves. 修复鼠标移出后高亮项仍然残留的问题 - 在ComboBox上添加isInteractingWithContent属性跟踪popup悬停状态,修改delegate的highlighted属性 - highlighted属性逻辑依赖isInteractingWithContent,鼠标离开时自动清除高亮 Log: 修复ComboBox的菜单项鼠标离开后高亮残留问题 Influence: ComboBox菜单项 PMS: BUG-304991
1 parent 1998e42 commit 42fd9ed

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

qt6/src/qml/ComboBox.qml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ T.ComboBox {
1919
property int maxVisibleItems : DS.Style.comboBox.maxVisibleItems
2020
property D.Palette separatorColor: DS.Style.comboBox.edit.separator
2121
property var horizontalAlignment: control.flat ? Text.AlignRight : Text.AlignLeft
22+
property bool isInteractingWithContent: false
2223
opacity: enabled ? 1.0 : 0.4
2324

2425
implicitWidth: DS.Style.control.implicitWidth(control)
@@ -36,7 +37,7 @@ T.ComboBox {
3637
useIndicatorPadding: true
3738
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
3839
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
39-
highlighted: control.highlightedIndex === index
40+
highlighted: control.isInteractingWithContent ? control.highlightedIndex === index : false
4041
hoverEnabled: control.hoverEnabled
4142
autoExclusive: true
4243
checked: control.currentIndex === index
@@ -169,6 +170,17 @@ T.ComboBox {
169170
rightMargin: DS.Style.popup.margin
170171
palette: control.palette
171172
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
173+
onClosed: control.isInteractingWithContent = false
174+
Connections {
175+
target: control
176+
function onHighlightedIndexChanged() {
177+
if (control.highlightedIndex >= 0)
178+
control.isInteractingWithContent = true
179+
}
180+
}
181+
HoverHandler {
182+
onHoveredChanged: control.isInteractingWithContent = hovered
183+
}
172184
contentItem: ArrowListView {
173185
clip: true
174186
maxVisibleItems: control.maxVisibleItems

0 commit comments

Comments
 (0)