How can I grab keyboard input event without showing widget?
-
Hello.
I using Qt 4.8.3 + DirectFB on embedded system(ARM-Core).
When I run my application, that has QMainApplication and widgets.
But all widgets are hiding.I want to show widgets when I push keyboard.
At this time, how can I grab keyboard input on QMainApplication?Thank you.
-
There's no QMainApplication class in Qt.
You can intercept all the app keyboard in a couple of ways.
One of them is installing an event filter on theqApp
object and fishing forQEvent::KeyPress
there. -
@Chris-Kawa
Thank you for reply.
I made mistake. I mean QApplication, not QMainApplication.So, I using test code like below link.
http://www.codeprogress.com/cpp/libraries/qt/showQtExample.php?key=QApplicationInstallEventFilter&index=188When I call "main.show()", then eventFilter-KeyPress- working well.
But delete "main.show()", then eventFilter-KeyPress not triggered.Is there no way grab keyboard input without showing widget?
Thank you.
-
Oh, I misunderstood then.
Qt can only expose events it receives from the OS. An app that does not have any windows does not receive any keyboard events from OS.For that you would have to hook into the keyboard events directly, which is highly platform specific and beyond what Qt provides.
You might look into 3rd party libraries for this functionality, for example QxtGlobalShortcut, but you'd have to check if it's available for your target platform. -
@Chris-Kawa
I add a widget that always showing in geometry(0,0,1,1).
This widget grab keyboard input and pass to QApplication.
It not perfect but looks okay for my target platform :-).Thank you for kind reply and have a good day.