[Qt-interest] QWidget::grabKeyboard() and window managers
Pedro Lopez-Cabanillas
pedro.lopez.cabanillas at gmail.com
Sat Jun 6 13:24:28 CEST 2009
Hi,
I've made an application based on Qt4, a virtual MIDI piano keyboard
(http://vmpk.sourceforge.net) allowing the users to press the alphanumeric
computer keys to play MIDI notes on MIDI synths. There is a configurable
option "Grab Keyboard" wanted by most users. I've implemented it using
QWidget::grabKeyboard(). Enabling this option, the piano widget should
receive all key events even when it is not focused. This allows for instance
use the mouse on other widgets like the volume knob without having to click
on the piano again to give it back the focus.
This feature works in Windows and Mac OSX limited to the current application,
so the keyboard is not globally grabbed. It works very well (with global
grab) in Linux using KDE3/4 desktops with the standard kwin window manager.
It also works with Enlightenment and Window Maker, but fails in Metacity,
Compiz and some other window managers. In other words: it is broken for most
Gnome users. Using this option also prevents normal usage of the drop down
menus on GTK2 applications.
I've seen that QWidget::grabKeyboard() is implemented in Qt/X11 using
XGrabKeyboard(3), a public and documented X11 API function. Do you know why
those WMs and toolkit don't support it? Is there any alternative? Can you
give me some advice?
Regards,
Pedro
More information about the Qt-interest-old
mailing list