Solved How to use the OS back button on QML Loader component change and on SwipeView move?
-
Hi,
at least for Android, when there is a back button, I'd like it be usable in my App when the view change so when I load another Item in a Loader or when the user swipe in the SwipeView.
Is there a way to achieve that?
At the moment the back button would close my App, whatever I do inside.Edit: I've tried to intercept it in Keys.onRelease but it is not working. The app closes.
focus: true Keys.onReleased: { console.log("Key pressed: "+event.key); if (event.key === Qt.Key_Back) { console.log("BACK"); } }
Edit2: I'm running on MIUI where I've changed the Back button to be a small swipe on the left part of the screen. How could I intercept that? sounds like its in Android level...
-
@mbruel where in you code is this?
it should be at the top most qml file(Window/ApplicationWindow)your code should work there. If not, you can also reacte to the on closing and set it to false, that at least will stop the app from closing
onClosing: { close.accepted = false }
-
@J-Hilk I don't use an ApplicationWindow, just a simple Window. my onReleased code is there. it is not triggered by the swipe action to do an Android back event.
the onClosing is working :)
I guess I can implement a state machine to remember the previous view (either due to a change of source of my main Loader or the index of the active SwipeView)
Cool, thanks ;)