Important: Please read the Qt Code of Conduct -

How to know when inputMethod is cancelled?

  • Hi!

    I have a custom widget that is using inputMethodEvent() and inputMethodQuery() to support, for example, Japanese input with mozc. Should eventually support different input methods also on Windows and Mac but for now I have just tested with Linux.

    I receive preedit text and render it to the widget at correct position. Also when event with commit text comes it is handled about ok. But how do I know if user cancelled the input method, for example by pressing esc? There does not seem to be any cancel signal in QInputMethod or in QWidget and the inputMethodEvent is not called in that case at all.

    I did little bit of research on how it works elsewhere. In some non-Qt application pressing esc cancelled the input method dialog (the one with possible composed input choises) and reset the state back to original. In qt application pressing the esc seemed to leave the preedit text in place although in somewhat strange states. For example moving cursor around it seemed to be odd. This also happened in QLineEdit standard in my own application.

    I have Qt version 5.9.5 which was installed by Ubuntu. I did some quick searches from Qt bugreports but failed to find anything but perhaps I did not search hard enough.

    So, if there is someone who could give some insight in this I would be very happy.

  • After some though I realized this could also be a bug in mozc. I setup Anthy and with that things where bit better: now if I cancelled input I also received inputMethodEvent with both preedit and commit texts set to empty strings. If I used that as a que to reset the status all seemed work ok.

    Still, some other non-Qt applications seemed to work better even with mozc so I'm still not sure if there is something Qt should be doing differently here. And I still haven't checked any other platforms.

Log in to reply