简体   繁体   中英

why qml virtualkeyboard is not show after click on edit text ,while I call plugin in .pro and main.cpp

I use open source qt5.9 for an embedded device. I wanna to use virtual keyboard in my qml project. I know I should add a static link in .pro file like :

static {
    QT += svg
    QTPLUGIN += qtvirtualkeyboardplugin
}

and also add

#include <QGuiApplication>
#include <QQmlApplicationEngine>

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

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;
    return app.exec();
}

to main.cpp file to use the virtual keyboard. but my virtual keyboard does not fire when I click on my text object:

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.VirtualKeyboard 2.1

Window {
    visible: true
    width: 640
    height: 480

        TextInput {
            id: textInput;
            text:"ssssss"
            height: 120;
            width: parent.width - 2;
            anchors.bottom: keyboard.top
            color: "#000000"; // black

            // http://doc.qt.io/qt-5/qinputmethod.html#properties
            focus: Qt.inputMethod.visible;

            verticalAlignment: TextInput.AlignVCenter;
        }
}

It solved.
just put the kind of input for each lineedit . like this :

InputPanel{
        id:inputpanel
        visible:active
        y:active?parent.height - inputpanel.height : parent.height
        anchors.left: parent.left
        anchors.right: parent.right

    }
    TextInput{
        id:input
        inputMethodHints: Qt.ImhDigitsOnly
        focus: Qt.inputMethod.visible;
        text: "123211"

    }
    TextInput{
        id:input2
        anchors.top:input.bottom
        inputMethodHints: Qt.ImhLowercaseOnly
        focus: Qt.inputMethod.visible;
        text: "123211"

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM