Qt.inputMethod.show()不显示任何键盘

时间:2015-02-23 10:39:40

标签: qt qml qt5 qtquick2

考虑"属性和方法的变化"来自here

  

已删除TextInput和TextEdit的openSoftwareInputPanel()和closeSoftwareInputPanel()方法。使用新的Qt.inputMethod属性并调用Qt.inputMethod.show()Qt.inputMethod.hide()来显示和隐藏虚拟键盘。

我已经写了下面这个简单的例子。

import QtQuick 2.3
import QtQuick.Window 2.2

Window
{
    id:         root
    visible:    true
    width:      600
    height:     557

    Rectangle
    {
        id:           numberInputBox
        height:       500
        width:        300
        border.color: "green"

        TextInput
        {
            id:             textInput
            font.pixelSize: 20
            cursorVisible:  true
            height: 500
            width: 300

            MouseArea
            {
                anchors.fill: parent
                onClicked:
                {
                    Qt.inputMethod.show()
                    console.log("getPrinted")
                }
            }
        }
    }
}

虽然来自console.log的文字被打印,但我在屏幕上看不到任何键盘。


更新:

我试过了:

import QtQuick 2.3
import QtQuick.Window 2.2

Window
{
    id:         root
    visible:    true
    width:      600
    height:     557

    Rectangle
    {
        id:           numberInputBox
        height:       500
        width:        300
        border.color: "green"
        property string numericText

        TextInput
        {
             id:             textInput
             text:           parent.numericText
             focus:          true
             activeFocusOnPress: true
             font.pixelSize: 20
             cursorVisible:  false

             MouseArea
             {
                 anchors.fill: parent
                 onClicked:
                 {
                     Qt.inputMethod.show ()
                     console.log("fsdfsdf")
                 }
             }
        }
    }
}

同样,文本被打印但键盘没有显示。 我使用的是Qt 5.4和QtCreator 3.3.0的Ubuntu 14.04.1 LTS

2 个答案:

答案 0 :(得分:1)

正如评论中所述,Qt Virtual Keyboard仅适用于Qt的顶级许可版本,即“专业”和“企业”版本,{{3}中提供的功能表清楚地证明了这一点。 }。

“社区版”(Qt的开源版)不包括键盘。因此,在桌面系统上,物理键盘是唯一可用的输入选项。不同的是,在移动平台中,Qt默认挂接本机虚拟键盘系统,无需调用Qt.inputMethod。鉴于此,问题中的例子可以简单地改写如下:

import QtQuick 2.3
import QtQuick.Window 2.2

Window
{
    id:         root
    visible:    true
    width:      600
    height:     557

    Rectangle
    {
        id:           numberInputBox
        height:       500
        width:        300
        border.color: "green"
        property string numericText

        TextInput
        {
             id:             textInput
             text:           parent.numericText
             focus:          true
             activeFocusOnPress: true
             font.pixelSize: 20
             cursorVisible:  false  
        }
    }
}

在点击TextInput后,在WinPhone,Android或iOS设备上执行此示例将正确显示本机虚拟键盘。

答案 1 :(得分:0)

我认为这是因为您需要提供TextInput焦点:

focus: true

这适用于我的桌面,我知道测试它的唯一方法是使用Qt's Virtual Keyboard(并在运行应用程序之前设置QT_IM_MODULE=qtvirtualkeyboard),正如BaCaRoZzo已经提到的那样。在具有原生虚拟键盘的平台上,例如Android,显式调用Qt.inputMethod.show()是不必要的。

相关问题