Qt World Summit: Register Today!

Custom Input Method

  • Hello,
    I would like to create a custom input method for applications that use the Qt for gui.
    What I have learned so far is that I have to subclass the QInputContext (in QT4) and I found this example http://qt-project.org/doc/qt-4.8/tools-inputpanel.html which kind of helps. But is it possible to make other applications use this custom input context without altering the source code?
    Thanks for any replies.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK yes, this will require you to create a QInputContextPlugin and then store that plugin in the proper places so Qt can load it.

  • Thank you, but how do I make all the desktop applications build on Qt use this plugin and the input context it represents?

  • Lifetime Qt Champion

    Can you describe your use case with OS and Qt version ?

  • Well I would like to create input method that would automatically substitute abbreviated words with full lenght words. It should work as implementation of "zavpis" which is a system of abbreviations developed for quicker keyboard input in the czech language.
    OS: Slackware 14.0
    Qt 4.8.2

  • Lifetime Qt Champion

    Then you can install the plugin in your distribution Qt's and all application will use it

  • So I have built a simple input context plugin and put it into QT4DIR/plugins/inputmethods
    How do I find out if qt has loaded the plugin? I cant get any application use this plugin. Cant find any qt setting which would make it use this plugin.

  • Lifetime Qt Champion

    start your application with the environment variable: QT_DEBUG_PLUGINS=1 to see what is happening with the plugins

  • Oh thank you for your patience, QT_DEBUG_PLUGINS=1 revealed that the applications look for implementation of reset() method in the QInputContext subclass which they didnt find. So I just put there simple void reset(){} and it works fine now.
    Anyway I think there is a little gap in the documentation as I never read anywhere that the input method plugins would get loaded in any application that has an input widget. I was near thinking that only implementation of XIM protocol would meet my requirements.

  • Lifetime Qt Champion

    Something strange here, reset is a pure virtual function, so to build your QInputContext inherited class you should have implemented this method.

    Did you read the "Plugin Classes" page in the documentation ? Might contain more information.

Log in to reply