Search code examples
qtqmlqt5qtvirtualkeyboard

QT5.8. custom Virtual keyboard including


I'm writing a custom virtual keyboard, which based on QtVirtualKeyboard. For my project I would need to be able to use my version of keyboard.

But the only method, which i found is recompile project and replace original "qtvirtualkeyboardplugin.dll" in "mingw53_32\plugins\platforminputcontexts" on my version of "qtvirtualkeyboardplugin.dll". And use the qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); function in main.cpp

After hours of reading the docs and trying various things I'm still cannot find method to use custom keyboard localy, without deleting original "qtvirtualkeyboardplugin.dll".


Solution

  • I'm assuming that you've forked the code, in which case the following modifications seem to be enough to get a differently named plugin to be installed to plugins/platforminputcontexts:

    • Rename qtvirtualkeyboard/src/virtualkeyboard/qtvirtualkeyboard.json to qtvirtualkeyboard/src/virtualkeyboard/customvirtualkeyboard.json.
    • In customvirtualkeyboard.json, rename the qtvirtualkeyboard key to customvirtualkeyboard.
    • In qtvirtualkeyboard/src/virtualkeyboard/plugin.cpp, change the contents of the pluginName string to customvirtualkeyboard.
    • In qtvirtualkeyboard/src/virtualkeyboard/plugin.h, change the FILE string to customvirtualkeyboard.
    • In src/virtualkeyboard/virtualkeyboard.pro, change TARGET = qtvirtualkeyboardplugin to TARGET = customvirtualkeyboardplugin. This affects the name of the installed .dll, .lib, etc. that you see in plugins/platforminputcontexts.

    Here are the changes as a Git diff:

    diff --git a/src/virtualkeyboard/customvirtualkeyboard.json b/src/virtualkeyboard/customvirtualkeyboard.json
    new file mode 100644
    index 0000000..9ef7a87
    --- /dev/null
    +++ b/src/virtualkeyboard/customvirtualkeyboard.json
    @@ -0,0 +1,3 @@
    +{
    +    "Keys": [ "customvirtualkeyboard" ]
    +}
    diff --git a/src/virtualkeyboard/plugin.cpp b/src/virtualkeyboard/plugin.cpp
    index 73ddeab..4abe9a4 100644
    --- a/src/virtualkeyboard/plugin.cpp
    +++ b/src/virtualkeyboard/plugin.cpp
    @@ -76,7 +76,7 @@ using namespace QtVirtualKeyboard;
    
     Q_LOGGING_CATEGORY(qlcVirtualKeyboard, "qt.virtualkeyboard")
    
    -static const char pluginName[] = "qtvirtualkeyboard";
    +static const char pluginName[] = "customvirtualkeyboard";
     static const char inputMethodEnvVarName[] = "QT_IM_MODULE";
     static const char pluginUri[] = "QtQuick.VirtualKeyboard";
     static const char pluginSettingsUri[] = "QtQuick.VirtualKeyboard.Settings";
    diff --git a/src/virtualkeyboard/plugin.h b/src/virtualkeyboard/plugin.h
    index 08074d1..19593a4 100644
    --- a/src/virtualkeyboard/plugin.h
    +++ b/src/virtualkeyboard/plugin.h
    @@ -38,7 +38,7 @@
     class QVirtualKeyboardPlugin : public QPlatformInputContextPlugin
     {
         Q_OBJECT
    -    Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "qtvirtualkeyboard.json")
    +    Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "customvirtualkeyboard.json")
    
     public:
         QStringList keys() const;
    diff --git a/src/virtualkeyboard/qtvirtualkeyboard.json b/src/virtualkeyboard/qtvirtualkeyboard.json
    deleted file mode 100644
    index 76d1706..0000000
    --- a/src/virtualkeyboard/qtvirtualkeyboard.json
    +++ /dev/null
    @@ -1,3 +0,0 @@
    -{
    -    "Keys": [ "qtvirtualkeyboard" ]
    -}
    diff --git a/src/virtualkeyboard/virtualkeyboard.pro b/src/virtualkeyboard/virtualkeyboard.pro
    index 4f3ca69..e9b0ff9 100644
    --- a/src/virtualkeyboard/virtualkeyboard.pro
    +++ b/src/virtualkeyboard/virtualkeyboard.pro
    @@ -1,4 +1,4 @@
    -TARGET  = qtvirtualkeyboardplugin
    +TARGET  = customvirtualkeyboardplugin
     DATAPATH = $$[QT_INSTALL_DATA]/qtvirtualkeyboard
    
     QMAKE_DOCS = $$PWD/doc/qtvirtualkeyboard.qdocconf
    

    Remember that if you're using an open source license, you have to make modifications to Qt code available to users of your application.