Qt Virtual Keyboard in QQuickWidget

夙愿已清 提交于 2021-02-19 06:23:08

问题


It is possible to show Virtual Keyboard in QQuickWidget or in QWidget?

I have QWidget application and I need to have better control where VirtualKeyboard is shown.

Today I spend all my day to find a solution, unfortunately without success.


回答1:


The following code shows that it is valid to use virtualkeyboard in QQuickWidget.

main.cpp

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWidget>

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QQuickWidget widget;
    widget.setResizeMode(QQuickWidget::SizeRootObjectToView);
    widget.setSource(QStringLiteral("qrc:/main.qml"));
    widget.show();
    return app.exec();
}

main.qml

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.VirtualKeyboard 2.14

Rectangle {
    id: window
    width: 640
    height: 480

    TextEdit{
        text: "Hello world"
        anchors.centerIn: parent
    }

    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: window.height
        width: window.width

        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: window.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
    }
}

qml.qrc

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>
</RCC>

59777221.pro

QT += quickwidgets virtualkeyboard
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES +=  main.cpp
RESOURCES += qml.qrc
├── 59777221.pro
├── main.cpp
├── main.qml
└── qml.qrc



来源:https://stackoverflow.com/questions/59777221/qt-virtual-keyboard-in-qquickwidget

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