View Full Version : Qt on Linux and dead keys

17th December 2010, 23:31

I have a QWidget which receives keypress events and shows the text received on the console (using qDebug() << event->text()).

When I run the code on Windows, when pressing the dead key '`' followed by the 'a' key, the widget receives an event with the text() 'á', which is the right way.

However, when running the same software on Linux, the widget receives two events, one with the text() '`' and another one with the text() 'a'.

I tried enabling keyboard event compression but it didn't change the behaviour. The locale() seems to be the right one (at least the country and language are the right ones) and the rest of the apps that I run on Linux (like Qt Creator for instance) work as expected.

Where can I look for the problem?

Thanks in advance!

18th December 2010, 00:02
Does your console support output of such characters?

This might be helpful (http://www.faqs.org/docs/Linux-HOWTO/Keyboard-and-Console-HOWTO.html).

18th December 2010, 11:32
My console (ctrl+alt+f1) and the emulators (xterm, gnome-terminal) work as expected (Ã instead of `a).

20th December 2010, 22:52
I have been researching a little and I found several differences between typical input widgets and my widget.

If I use a QPlainTextEdit widget, everything works OK in my app. However, when using this widget and a QWidget next to it, while the QPlainTextEdit may receive "Ã ", the QWidget receives "`" followed by "a". I think that mayble using the right QInputMethod or locale or something may do the trick, but I'm not sure. Any ideas?


Added after 1 14 minutes:

Fixed! Well, sort of...

I had to set the Qt::WA_InputMethodEnabled attribute and, after that, reimplement the inputMethodEvent(QInputMethodEvent *e) method. This way, when receiving dead keys or some kind of special key events, the "input method" (ibus in my case, ubuntu) handles the special key event and lets the widget capture the text through the QInputMethodEvent::commitString() method.

I hope it helps someone :)