c++ - 为什么在单击编辑文本后不显示 qml 虚拟键盘,而我在 .pro 和 main.cpp 中调用插件

标签 c++ qt qml virtual-keyboard

我为嵌入式设备使用开源 qt5.9。 我想在我的 qml 项目中使用虚拟键盘。我知道我应该在 .pro 文件中添加一个静态链接,例如:

static {
    QT += svg
    QTPLUGIN += qtvirtualkeyboardplugin
}

同时添加

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

到 main.cpp 文件以使用虚拟键盘。但是当我点击我的文本对象时我的虚拟键盘没有触发:

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

最佳答案

解决了。
只需为每个 lineedit 输入那种输入。像这样:

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"

    }

关于c++ - 为什么在单击编辑文本后不显示 qml 虚拟键盘,而我在 .pro 和 main.cpp 中调用插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52125930/

相关文章:

c++ - 如何逐点查看多边形

qt - 当 QML 项目的大小发生变化时,如何保持其右上角的位置?

c++ - Qt4.8中处理鼠标滚轮事件

c++ - 检查 C++ 指针是否有效(在 Objective-C(++) 中)

c++ - Visual Studio 2017 在 extern "C"中使用模板时出现不正确的错误

c++ - OpenCV C++ - 具有不规则边的矩形检测

qml - 手动更新/重新绘制项目

c++ - 你如何在 Qt 中获得一个小部件的 child ?

c++ - 在 C++ 中刷新组合框?

c++ - 将 QList 迭代器转换为索引