From 6fd9e9164b0bd928bea1245f19cb67681b8dcbfb Mon Sep 17 00:00:00 2001
From: Shawn Rutledge <shawn.rutledge@digia.com>
Date: Fri, 10 Oct 2014 10:50:20 +0200
Subject: [PATCH] Custom filled dialog example: handle back button to close

On Android, it should prefer to close the dialog rather than get stuck
or exit the application.  (It was already possible to close the dialog
by tapping outside, though.)  The back button can also be used on
other platforms which have them (e.g. multimedia keyboards on desktop).

Change-Id: I19d2ad62ff370fa467d80d51d73cb95fd5830bed
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
---
 examples/quick/dialogs/systemdialogs/CustomDialogs.qml | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/examples/quick/dialogs/systemdialogs/CustomDialogs.qml b/examples/quick/dialogs/systemdialogs/CustomDialogs.qml
index 405dece3b..cc91fbb42 100644
--- a/examples/quick/dialogs/systemdialogs/CustomDialogs.qml
+++ b/examples/quick/dialogs/systemdialogs/CustomDialogs.qml
@@ -135,6 +135,7 @@ Item {
         id: filledDialog
         modality: dialogModal.checked ? Qt.WindowModal : Qt.NonModal
         title: customizeTitle.checked ? windowTitleField.text : "Customized content"
+        onRejected: lastChosen.text = "Rejected"
         contentItem: Rectangle {
             color: "lightskyblue"
             implicitWidth: 400
@@ -144,8 +145,8 @@ Item {
                 color: "navy"
                 anchors.centerIn: parent
             }
-            focus: true
-            Keys.onEscapePressed: filledDialog.close()
+            Keys.onEscapePressed: filledDialog.reject()
+            Keys.onBackPressed: filledDialog.reject() // especially necessary on Android
         }
     }
 
-- 
GitLab