From 10d1e17325e6058e0448081d5b68bdb29d9cf440 Mon Sep 17 00:00:00 2001
From: Pierre Lamot <pierre@videolabs.io>
Date: Fri, 10 Sep 2021 11:35:06 +0200
Subject: [PATCH] qml: fix backspace close the SearchBox on Windows

fix: #26043
---
 modules/gui/qt/widgets/qml/SearchBox.qml | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/modules/gui/qt/widgets/qml/SearchBox.qml b/modules/gui/qt/widgets/qml/SearchBox.qml
index 780b56719bc4..f1fd82be00b5 100644
--- a/modules/gui/qt/widgets/qml/SearchBox.qml
+++ b/modules/gui/qt/widgets/qml/SearchBox.qml
@@ -134,28 +134,20 @@ FocusScope {
                 Navigation.parentItem: root
                 Navigation.leftItem: icon
                 Navigation.rightItem: clearButton.visible ? clearButton : null
+                Navigation.cancelAction: function() { _expanded = false }
                 Keys.priority: Keys.AfterItem
                 Keys.onPressed: {
-                    //don't use KeyHelper.matchCancel here as we don't want to match Backspace
-                    if (event.key === Qt.Key_Back
-                        || event.key === Qt.Key_Cancel
-                        || event.matches(StandardKey.Back)
-                        || event.matches(StandardKey.Cancel))
-                    {
-                        event.accepted = true
+                    //we don't want Navigation.cancelAction to match Backspace
+                    if (event.matches(StandardKey.Backspace)) {
+                        return
                     }
                     Navigation.defaultKeyAction(event)
                 }
 
                 Keys.onReleased: {
-                    //don't use KeyHelper.matchCancel here as we don't want to match Backspace
-                    if (event.key === Qt.Key_Back
-                        || event.key === Qt.Key_Cancel
-                        || event.matches(StandardKey.Back)
-                        || event.matches(StandardKey.Cancel))
-                    {
-                        _expanded = false
-                        event.accepted = true
+                    //we don't want Navigation.cancelAction to match Backspace
+                    if (event.matches(StandardKey.Backspace)) {
+                        return
                     }
                     Navigation.defaultKeyReleaseAction(event)
                 }
-- 
GitLab