Unsolved Focus
-
Hello, I would like to control the focus of my application, when it is executed that the application has the focus and when I am outside the application, I lose it and all the processes stop their execution.
-
I'm not sure I understand if you want to actually control the focus or get a notification when it changes.
For the second case take a look at focusWindowChanged signal. You will get your app's window that receives focus or nullptr if your app looses it.
-
@Chris-Kawa Both things, both controlling the focus and being notified of the change
-
Then for notification you can use the signal I mentioned, but moving focus away from your app will be different for different platforms. Also that's not something applications often do and it can be annoying to users if applications change focus without their actions. What's your use case?
-
@Chris-Kawa For windows and android
-
No, I meant why do you need to manually change focus between apps.
-
@Chris-Kawa Because my application is a text editor for people with functional diversity and it has very specific configurations and I need to have control of the focus.
-
@Chris-Kawa Could you provide me with an example of the operation of focusWindowChanged.
-
There's not much to show. It's just a regular Qt signal on the application object, but here's a simple example:
#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel label; label.show(); QObject::connect(&a, &QGuiApplication::focusWindowChanged, [&](QWindow* window) { label.setText(window ? "App has focus" : "App doesn't have focus"); }); return a.exec(); }
-
@Chris-Kawa Thanks this has helped me, and on the subject of changing the focus you know how I could do it.