qt 虚拟键盘不显示

qt virtual keyboard does not show up

我正在尝试在 raspberry pi 上使用 qt 虚拟键盘,但在调用键盘时遇到问题。

我已经如下配置项目以允许使用虚拟键盘:

//In the PRO file
QT += qml quick quickcontrols2 xml
static {
    QT += svg
    QTPLUGIN += qtvirtualkeyboardplugin
}

CONFIG += c++11 disable-desktop

我认为disable-desktop应该足以召唤虚拟键盘,至少我是这么认为的。

我的 main 文件中的第一行是:

qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); 

这确保模块已加载。我已经验证,如果没有这一行,带有虚拟键盘模块的程序 barfs not found 错误。

现在,我有一个简单的组件,它有一个文本字段:

import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1
import QtQuick.VirtualKeyboard 2.1

TextField {
            id: idField
            width: 80
            height: 30
            placeholderText: qsTr("ID")
            Layout.maximumHeight: 30
            Layout.minimumHeight: 30
            Layout.minimumWidth: 80
            Layout.maximumWidth: 80
            focus: true
            anchors.horizontalCenter: parent.horizontalCenter
            inputMethodHints: Qt.ImhDigitsOnly
        }

当我点击它时,键盘没有出现。我想知道是否需要进行其他设置才能召唤键盘?

disable-desktop 应该在构建 Qt 虚拟键盘之前作为参数传递给 qmake,而不是使用键盘的应用程序:

qmake CONFIG+=disable-desktop qtvirtualkeyboard.pro

但是,我认为 this code 会自动处理嵌入式设备的问题(这意味着 pre-built/packaged Qt 应该可以工作)。

使用disable-desktop时,由您提供InputPanel:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.VirtualKeyboard 2.0

ApplicationWindow {
    id: window
    visible: true
    width: 640
    height: 480

    TextField {
        anchors.centerIn: parent
    }

    InputPanel {
        id: inputPanel
        z: 89
        y: active ? parent.height - height : parent.height
        anchors.left: parent.left
        anchors.right: parent.right
    }
}

这个here. This部分文档有更高级的例子,下一章也有例子:

In the application integration method, the application is required to create an instance of InputPanel as explained in the following chapter.