Skip to content

Commit e136cd3

Browse files
committed
fix(ComboBox): fix the issue of highlighted state lingering after
mouse leaves menu items Root cause: The delegate.highlighted is bound to control.highlightedIndex (read-only). When the mouse leaves the popup area, this value is not automatically reset, causing the highlighted state to persist. Fix approach: - Add a new contentHovered property to the popup to track whether the mouse is within the popup list area - Use HoverHandler in Qt6 to synchronize the contentHovered state - Use MouseArea (acceptedButtons: Qt.NoButton) in Qt5 to synchronize the contentHovered state - Change delegate.highlighted to popup.contentHovered && control.highlightedIndex === index Log: Fixed the issue of lingering highlight on ComboBox menu items after mouse leaves Influence: ComboBox menu items fix(ComboBox): 修复菜单项鼠标离开后高亮残留问题 根因:delegate.highlighted 绑定 control.highlightedIndex(只读), 鼠标离开弹出区域时该值不会自动重置,导致高亮状态持续残留。 修复方案: - 为 popup 新增 contentHovered 属性,追踪鼠标是否在弹出列表区域内 - Qt6 版本使用 HoverHandler 同步 contentHovered 状态 - Qt5 版本使用 MouseArea(acceptedButtons: Qt.NoButton)同步 contentHovered 状态 - 将 delegate.highlighted 改为 popup.contentHovered && control.highlightedIndex === index Log: 修复ComboBox的菜单项鼠标离开后高亮残留问题 Influence: ComboBox菜单项 PMS: BUG-306683
1 parent 1998e42 commit e136cd3

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

qt6/src/qml/ComboBox.qml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ T.ComboBox {
3636
useIndicatorPadding: true
3737
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
3838
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
39-
highlighted: control.highlightedIndex === index
39+
highlighted: popup.contentHovered && control.highlightedIndex === index
4040
hoverEnabled: control.hoverEnabled
4141
autoExclusive: true
4242
checked: control.currentIndex === index
@@ -169,13 +169,17 @@ T.ComboBox {
169169
rightMargin: DS.Style.popup.margin
170170
palette: control.palette
171171
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
172+
property bool contentHovered: false
172173
contentItem: ArrowListView {
173174
clip: true
174175
maxVisibleItems: control.maxVisibleItems
175176
view.model: control.delegateModel
176177
view.currentIndex: control.highlightedIndex
177178
view.highlightRangeMode: ListView.ApplyRange
178179
view.highlightMoveDuration: 0
180+
HoverHandler {
181+
onHoveredChanged: popup.contentHovered = hovered
182+
}
179183
}
180184

181185
background: FloatingPanel {

src/qml/ComboBox.qml

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

@@ -31,7 +31,7 @@ T.ComboBox {
3131
width: parent.width
3232
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
3333
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
34-
highlighted: control.highlightedIndex === index
34+
highlighted: popup.contentHovered && control.highlightedIndex === index
3535
hoverEnabled: control.hoverEnabled
3636
autoExclusive: true
3737
checked: control.currentIndex === index
@@ -146,14 +146,22 @@ T.ComboBox {
146146
}
147147

148148
popup: Popup {
149+
id: popup
149150
implicitWidth: control.width
151+
property bool contentHovered: false
150152
contentItem: ArrowListView {
151153
clip: true
152154
maxVisibleItems: control.maxVisibleItems
153155
view.model: control.delegateModel
154156
view.currentIndex: control.highlightedIndex
155157
view.highlightRangeMode: ListView.ApplyRange
156158
view.highlightMoveDuration: 0
159+
MouseArea {
160+
anchors.fill: parent
161+
hoverEnabled: true
162+
acceptedButtons: Qt.NoButton
163+
onContainsMouseChanged: popup.contentHovered = containsMouse
164+
}
157165
}
158166

159167
background: FloatingPanel {

0 commit comments

Comments
 (0)