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

坚强是说给别人听的谎言 提交于 2021-01-28 05:07:30

问题


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.

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();
}

来源:https://stackoverflow.com/questions/65190871/how-to-enable-textfield-selection-handlers-with-qtvirtualkeyboard-on-a-qquickwid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!