From 57f56cc23ff7033c673d8f887c22d625e4c40425 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Mon, 2 Feb 2026 13:44:51 +0800 Subject: [PATCH] fix: Fix the issue where removing an item from the dropdown list does not cancel the highlight Fix the issue where removing an item from the dropdown list does not cancel the highlight Log: Fix the issue where removing an item from the dropdown list does not cancel the highlight pms: BUG-306683 BUG-304991 --- qt6/src/qml/ArrowListView.qml | 6 ++++++ qt6/src/qml/ComboBox.qml | 4 +++- qt6/src/qml/Menu.qml | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/qt6/src/qml/ArrowListView.qml b/qt6/src/qml/ArrowListView.qml index 49959471..699e4589 100644 --- a/qt6/src/qml/ArrowListView.qml +++ b/qt6/src/qml/ArrowListView.qml @@ -14,10 +14,16 @@ FocusScope { property int maxVisibleItems : DS.Style.arrowListView.maxVisibleItems property int itemHeight: DS.Style.arrowListView.itemHeight property alias view: itemsView + property bool hovered: hoverHandler.hovered implicitWidth: Math.max(DS.Style.arrowListView.width, contentLayout.implicitWidth) implicitHeight: contentLayout.implicitHeight + HoverHandler { + id: hoverHandler + target: itemsView + } + ColumnLayout { id: contentLayout anchors.fill: parent diff --git a/qt6/src/qml/ComboBox.qml b/qt6/src/qml/ComboBox.qml index f8f46483..b42267ea 100644 --- a/qt6/src/qml/ComboBox.qml +++ b/qt6/src/qml/ComboBox.qml @@ -4,6 +4,7 @@ import QtQuick import QtQuick.Layouts +import QtQuick.Controls import QtQuick.Templates as T import org.deepin.dtk 1.0 as D import org.deepin.dtk.style 1.0 as DS @@ -34,7 +35,7 @@ T.ComboBox { useIndicatorPadding: true text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null - highlighted: control.highlightedIndex === index + highlighted: (control.highlightedIndex === index) && (arrowListView.hovered || (subMenu && subMenu.visible)) hoverEnabled: control.hoverEnabled autoExclusive: true checked: control.currentIndex === index @@ -166,6 +167,7 @@ T.ComboBox { palette: control.palette implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width contentItem: ArrowListView { + id: arrowListView clip: true maxVisibleItems: control.maxVisibleItems view.model: control.delegateModel diff --git a/qt6/src/qml/Menu.qml b/qt6/src/qml/Menu.qml index 92155b3f..3b484a81 100644 --- a/qt6/src/qml/Menu.qml +++ b/qt6/src/qml/Menu.qml @@ -6,6 +6,7 @@ import QtQuick import QtQuick.Window import QtQuick.Layouts import QtQuick.Templates as T +import QtQuick.Controls import org.deepin.dtk 1.0 as D import org.deepin.dtk.style 1.0 as DS @@ -47,6 +48,28 @@ T.Menu { // QTBUG-99897 focus doesn't be clear. implicitWidth: viewLayout.implicitWidth implicitHeight: viewLayout.implicitHeight + + HoverHandler { + id: menuHoverHandler + target: viewLayout + onHoveredChanged: { + if (!hovered) { + var currentItem = control.itemAt(control.currentIndex) + var hasOpenSubMenu = false + + if (currentItem) { + if (currentItem.subMenu && currentItem.subMenu.visible) { + hasOpenSubMenu = true + } + } + + if (!hasOpenSubMenu) { + control.currentIndex = -1 + } + } + } + } + ColumnLayout { id: viewLayout spacing: 0