【问题标题】:qt virtual keyboard does not show upqt虚拟键盘不显示
【发布时间】:2017-07-10 16:32:46
【问题描述】:

我正在尝试在树莓派上使用 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 with the virtual keyboard module 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
        }

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

【问题讨论】:

    标签: qt qml qtvirtualkeyboard


    【解决方案1】:

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

    qmake CONFIG+=disable-desktop qtvirtualkeyboard.pro
    

    但是,我认为this code 会自动处理嵌入式设备的问题(这意味着预构建/打包的 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部分文档有提到,下一章也有例子:

    在应用程序集成方法中,应用程序需要创建一个InputPanel的实例,如下章所述。

    【讨论】:

    • 我已经在同一台设备上使用虚拟键盘尝试了 qt 示例,它们似乎可以正常工作,因此显然键盘构建正确。
    • 我忘记了一件非常重要的事情.. :D
    • 是的,就是这样。我完全错过了需要提供 InputPanel。
    猜你喜欢
    • 2015-01-02
    • 1970-01-01
    • 2020-10-09
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多