4

I am trying to make the QtVirtualKeyboard example work with QQuickWidget instead of QQuickView. For QuickView, I use the following main.cpp code, which works fine for me:

#include <QQuickView>
#include <QGuiApplication>
#include <QQmlEngine>

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QGuiApplication app(argc, argv);

    QQuickView view(QString("qrc:/%2").arg(MAIN_QML));
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.show();

    return app.exec();
}

I run into problems, when changing to QQuickWidgets with the following implementation of main.cpp:

#include <QQuickWidget>
#include <QApplication>
#include <QQmlEngine>

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QApplication app(argc, argv);

    QQuickWidget w(QString("qrc:/%2").arg(MAIN_QML));
    w.setResizeMode(QQuickWidget::SizeRootObjectToView);
    w.show();

    return app.exec();
}

When I hit the input fields, the virtual keyboard shows up, but when I start typing at the keyboard, I get the message "input method is not set", which seems to be related to the input method plugin. No chars appear in the input fields. Any ideas? The QML-code didn't change between the above variants of main.cpp

BTW: I am using Linux, gcc, Qt 5.9.0, EGLFS plugin

Thanks for any suggestions!

Regards, Patrick

Piotr Adam Milewski
  • 14,150
  • 3
  • 21
  • 42
pvb
  • 41
  • 3
  • I did some further tests and the same code works with Qt 5.8.0, but fails on 5.9.0 – pvb Jun 26 '17 at 06:13
  • Very strange bug: I used virtual keyboard normal in 5.12.x, then accidentally start to get these strange errors: `input method is not set`. Any updates how to fix this? – Aleksey Kontsevich May 14 '20 at 03:41

1 Answers1

1

Found the solution for QML looking through inputMethod documentation. Following workaround works for me:

TextArea {
    ...
    onActiveFocusChanged: {
        if(activeFocus) {
            Qt.inputMethod.update(Qt.ImQueryInput)
        }
    }
}

Works with other controls as well.

Of course InputPanel should be defined in ApplicationWindow like this:

ApplicationWindow {
...
    InputPanel {
        id: inputPanel
        ...
    }
}
Aleksey Kontsevich
  • 4,671
  • 4
  • 46
  • 101