Skip to content

Commit 561f621

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

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

qt6/src/qml/ComboBox.qml

Lines changed: 12 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 : false
4040
hoverEnabled: control.hoverEnabled
4141
autoExclusive: true
4242
checked: control.currentIndex === index
@@ -169,13 +169,24 @@ 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
173+
Connections {
174+
target: control
175+
function onHighlightedIndexChanged() {
176+
if (control.highlightedIndex >= 0)
177+
popup.contentHovered = true
178+
}
179+
}
172180
contentItem: ArrowListView {
173181
clip: true
174182
maxVisibleItems: control.maxVisibleItems
175183
view.model: control.delegateModel
176184
view.currentIndex: control.highlightedIndex
177185
view.highlightRangeMode: ListView.ApplyRange
178186
view.highlightMoveDuration: 0
187+
HoverHandler {
188+
onHoveredChanged: popup.contentHovered = hovered
189+
}
179190
}
180191

181192
background: FloatingPanel {

0 commit comments

Comments
 (0)