Skip to content

Commit 813e96c

Browse files
committed
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
1 parent efb8f50 commit 813e96c

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

qt6/src/qml/ArrowListView.qml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ FocusScope {
1414
property int maxVisibleItems : DS.Style.arrowListView.maxVisibleItems
1515
property int itemHeight: DS.Style.arrowListView.itemHeight
1616
property alias view: itemsView
17+
property bool hovered: hoverHandler.hovered
1718

1819
implicitWidth: Math.max(DS.Style.arrowListView.width, contentLayout.implicitWidth)
1920
implicitHeight: contentLayout.implicitHeight
2021

22+
HoverHandler {
23+
id: hoverHandler
24+
target: itemsView
25+
}
26+
2127
ColumnLayout {
2228
id: contentLayout
2329
anchors.fill: parent

qt6/src/qml/ComboBox.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import QtQuick
66
import QtQuick.Layouts
7+
import QtQuick.Controls
78
import QtQuick.Templates as T
89
import org.deepin.dtk 1.0 as D
910
import org.deepin.dtk.style 1.0 as DS
@@ -34,7 +35,7 @@ T.ComboBox {
3435
useIndicatorPadding: true
3536
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
3637
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
37-
highlighted: control.highlightedIndex === index
38+
highlighted: (control.highlightedIndex === index) && (arrowListView.hovered || (subMenu && subMenu.visible))
3839
hoverEnabled: control.hoverEnabled
3940
autoExclusive: true
4041
checked: control.currentIndex === index
@@ -166,6 +167,7 @@ T.ComboBox {
166167
palette: control.palette
167168
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
168169
contentItem: ArrowListView {
170+
id: arrowListView
169171
clip: true
170172
maxVisibleItems: control.maxVisibleItems
171173
view.model: control.delegateModel

qt6/src/qml/Menu.qml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import QtQuick
66
import QtQuick.Window
77
import QtQuick.Layouts
88
import QtQuick.Templates as T
9+
import QtQuick.Controls
910
import org.deepin.dtk 1.0 as D
1011
import org.deepin.dtk.style 1.0 as DS
1112

@@ -47,6 +48,28 @@ T.Menu {
4748
// QTBUG-99897 focus doesn't be clear.
4849
implicitWidth: viewLayout.implicitWidth
4950
implicitHeight: viewLayout.implicitHeight
51+
52+
HoverHandler {
53+
id: menuHoverHandler
54+
target: viewLayout
55+
onHoveredChanged: {
56+
if (!hovered) {
57+
var currentItem = control.itemAt(control.currentIndex)
58+
var hasOpenSubMenu = false
59+
60+
if (currentItem) {
61+
if (currentItem.subMenu && currentItem.subMenu.visible) {
62+
hasOpenSubMenu = true
63+
}
64+
}
65+
66+
if (!hasOpenSubMenu) {
67+
control.currentIndex = -1
68+
}
69+
}
70+
}
71+
}
72+
5073
ColumnLayout {
5174
id: viewLayout
5275
spacing: 0

qt6/src/qml/MenuItem.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ T.MenuItem {
2323
}
2424

2525
property D.Palette textColor: control.highlighted ? DS.Style.checkedButton.text
26-
: DS.Style.menu.itemText
26+
: DS.Style.menu.itemText
2727
property D.Palette subMenuBackgroundColor: DS.Style.menu.subMenuOpenedBackground
2828

2929
palette.windowText: D.ColorSelector.textColor

0 commit comments

Comments
 (0)