How to enable TextField selection handlers with QtVirtualKeyboard on a QQuickWidget?

231 views Asked by At

I am integrating QtVirtualKeyboard in my QML app and this causes selection handlers to appear in text fields when some text is selected as shown below.

enter image description here

However the handlers are not draggable if I integrate my QML app using a QQuickWidget. Instead it prints out an error: QMetaObject::invokeMethod: No such method QQuickWidget::inputMethodQuery(Qt::InputMethodQuery,QVariant)

Here is a minimal reproducible example:

main.cpp:

#include <QApplication>
#include <QQuickWidget>

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

    QApplication a(argc, argv);

    QQuickWidget quickWidget;
    quickWidget.setAttribute(Qt::WA_AcceptTouchEvents);
    quickWidget.setSource(QUrl("qrc:/main.qml"));
    quickWidget.show();

    return a.exec();
}

main.qml:

import QtQuick 2.0
import QtQuick.Controls 2.0

Page {
    TextField {
        selectByMouse: true
    }
}

The handlers work just fine if I use a QQuickView instead, by changing main.cpp like so:

#include <QApplication>
#include <QQuickView>
#include <QWidget>

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

    QApplication a(argc, argv);

    QQuickView quickView;
    quickView.setSource(QUrl("qrc:/main.qml"));

    QWidget::createWindowContainer(&quickView)->show();

    return a.exec();
}
0

There are 0 answers