Regaining Focus after asynchronous notification
-
Hello,
I have a QML application that is fairly large with several dialogs, controls, views, etc. I am trying to have an asynchronous notification that requires the user's acknowledgement to close a message box. The problem is, the user could be doing a number of different things when the notification happens and I need to know how to return focus to the previous item.I know how to test for active focus of any one item, using the activeFocus method of Item. However, I could be anywhere in the application so I really need more of a global pointer to the active focus item in the application. I haven't been able to find such a call in QML, so hopefully I missed it. Does anyone know if there is such a thing? All I want to do is save a reference to the current focus item, open my dialog, and return focus to the previous item when the user has clicked "ok".
Here is an example of how I dynamically create a dialog in another location and return focus back to the parent once the dialog is complete.
@var component = Qt.createComponent("SimpleDialog.qml");
if (component.status === Component.Ready) {
var dlg = component.createObject(container);
dlg.closed.connect(container.forceActiveFocus);
dlg.title = "SomethingHappened";
dlg.message = "Something happened.";
dlg.forceActiveFocus();
}
else {
console.log("Error loading SimpleDialog.qml:", component.errorString());
}@