Skip to content

Commit 8c8735d

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 8c8735d

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

qt6/src/qml/ComboBox.qml

Lines changed: 28 additions & 8 deletions
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
@@ -20,6 +21,7 @@ T.ComboBox {
2021
property D.Palette separatorColor: DS.Style.comboBox.edit.separator
2122
property var horizontalAlignment: control.flat ? Text.AlignRight : Text.AlignLeft
2223
opacity: enabled ? 1.0 : 0.4
24+
property bool forceNoHighlight: false
2325

2426
implicitWidth: DS.Style.control.implicitWidth(control)
2527
implicitHeight: DS.Style.control.implicitHeight(control)
@@ -34,7 +36,7 @@ T.ComboBox {
3436
useIndicatorPadding: true
3537
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
3638
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
37-
highlighted: control.highlightedIndex === index
39+
highlighted: !control.forceNoHighlight && control.highlightedIndex === index
3840
hoverEnabled: control.hoverEnabled
3941
autoExclusive: true
4042
checked: control.currentIndex === index
@@ -165,13 +167,31 @@ T.ComboBox {
165167
rightMargin: DS.Style.popup.margin
166168
palette: control.palette
167169
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
168-
contentItem: ArrowListView {
169-
clip: true
170-
maxVisibleItems: control.maxVisibleItems
171-
view.model: control.delegateModel
172-
view.currentIndex: control.highlightedIndex
173-
view.highlightRangeMode: ListView.ApplyRange
174-
view.highlightMoveDuration: 0
170+
contentItem: Item {
171+
implicitWidth: arrowListView.implicitWidth
172+
implicitHeight: arrowListView.implicitHeight
173+
174+
HoverHandler {
175+
id: comboBoxHoverHandler
176+
target: arrowListView
177+
onHoveredChanged: {
178+
if (!hovered) {
179+
control.forceNoHighlight = true
180+
} else {
181+
control.forceNoHighlight = false
182+
}
183+
}
184+
}
185+
186+
ArrowListView {
187+
id: arrowListView
188+
anchors.fill: parent
189+
clip: true
190+
maxVisibleItems: control.maxVisibleItems
191+
view.model: control.delegateModel
192+
view.highlightRangeMode: ListView.ApplyRange
193+
view.highlightMoveDuration: 0
194+
}
175195
}
176196

177197
background: FloatingPanel {

qt6/src/qml/Menu.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ T.Menu {
4747
// QTBUG-99897 focus doesn't be clear.
4848
implicitWidth: viewLayout.implicitWidth
4949
implicitHeight: viewLayout.implicitHeight
50+
51+
HoverHandler {
52+
id: menuHoverHandler
53+
target: viewLayout
54+
onHoveredChanged: {
55+
if (!hovered) {
56+
var currentItem = control.itemAt(control.currentIndex)
57+
var hasOpenSubMenu = false
58+
59+
if (currentItem) {
60+
if (currentItem.subMenu && currentItem.subMenu.visible) {
61+
hasOpenSubMenu = true
62+
}
63+
}
64+
65+
if (!hasOpenSubMenu) {
66+
control.currentIndex = -1
67+
}
68+
}
69+
}
70+
}
71+
5072
ColumnLayout {
5173
id: viewLayout
5274
spacing: 0

0 commit comments

Comments
 (0)