PDA

View Full Version : Window focus issues (How to force focus to a window?)



montylee
24th April 2009, 23:18
I have a non-fullscreen Qt application running on top of a browser on an embedded device.
Now, if i click outside the Qt application, it loses focus and doesn't get keyboard events. Is there any way to force focus so that it never loses focus even if someone clicks outside the Qt window?

When the application loses focus, i am able to trap the focus out event, but i don't know how to force the focus back to my application after trapping focus out event.

caduel
24th April 2009, 23:56
have you tried QWidget::grabKeyboard() or maybe QWidget::grabMouse()?

montylee
25th April 2009, 00:43
Actually i already tried grabKeyboard() before creating this thread. It was working on my desktop and i wasn't sure if it'll work on the embedded device properly.
But i just tested in on the device and it seems to work :)

The problem was getting the Window Deactivation event on the embedded device. The device doesn't have a window manager so i don't get any event when user clicks outside the window. So, i tried trapping FocusOut event instead and it's working fine.

I had some -ve thoughts about grabKeyboard that if i do grabKeyboard on my main widget in the Qt window, it won't allow me to transfer focus to other widgets, but it's working fine.

montylee
25th April 2009, 01:00
1 small query:
I am getting focus lost event when user clicks outside the Qt window.
Now, if the mouse cursor is not there i.e. someone disables the mouse cursor on the embedded device (since the device is touchscreen, the cursor may not be visible) i should still get the focus lost event, right?