【问题标题】:Qt TextField is not invoking the keyboard when launched on Android deviceQt TextField 在 Android 设备上启动时未调用键盘
【发布时间】:2016-05-06 18:18:27
【问题描述】:

我有一个简单的 QML 应用程序,它只显示一个 TextField

Rectangle {
    color: "#00000000"

    TextField {
        anchors.centerIn: parent
    }
}

我想,当我触摸TextField 时,Android 键盘会自动显示,但它没有发生。 我尝试在TextFieldComponent.onCompleted 和许多其他方法中使用focusQt.inputMethod.show()forceActiveFocus() 和许多其他方法,但无论如何都没有显示键盘。 尝试在其他设备和 Android 4.1-4.4 版本上使用应用程序,但结果始终相同 )))):

这是错误还是 TextField 的设置不正确?

【问题讨论】:

  • 您看到应用程序上显示了应用程序启动和文本字段,但单击文本字段并没有调出键盘?

标签: android qt qml qt5


【解决方案1】:

我也遇到过类似的问题,在

flags: Qt.FramelessWindowHint

在应用程序窗口中。 为 Android 删除它。它会影响 QML 中的所有文本输入。

删除后,您将获得适当的 android 系统事件通知(例如按返回键)作为奖励。

【讨论】:

【解决方案2】:

您的代码没有任何问题。 TextFiled {} 项目在安卓设备上操作时应该会自动启动键盘。我创建了一个简单的“Qt Quick Controls Application”并添加了您的代码,它对我有用,但是如果您还没有这样做的话,还有几点不足:

1. You have not set the Width/Height properties of the item properly.
2. Set anchors to your Rectangle item.

我对您的代码做了如下轻微修改:

Rectangle {
    color: "#00000000"
    anchors.fill: parent

    Row {
        anchors.centerIn: parent
        spacing: 10

        Text {
            id: textTitle
            text: "Text Field: "
            width: 100
            height: 100
            color: "black"
            font.pixelSize: 40
            horizontalAlignment: Text.AlignRight
            verticalAlignment: Text.AlignVCenter
        }

        TextField {
            id: textField

            width: 300
            height: 100
            text: ""
            font.pixelSize: 40
            placeholderText: qsTr("Enter Your Text")
            onEditingFinished: {
                console.log("Text entered: ", textField.text)
            }
        }
    }
}

我构建了这个应用程序的 Windows 桌面版本并验证它可以工作。另外,我已经在 Nexus 6 Android 模拟器上加载了这个应用程序。

非常重要的一点是您要加载应用程序的 Android 设备的 DPI(每英寸物理点数) 值。您的项目的Width/HeightText: Font Point size 值应根据您的应用程序将要部署的Android 设备的DPI 进行设置。如果不是这样,您可能会看到您的文本在真正的 android 设备上显得非常小,有时如果没有正确锚定,由于屏幕上只有一个 textField 项,因此很难在应用程序上注意到您的文本字段。

如果不能直接解决您的问题。希望这可以帮助您调试并得出解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    相关资源
    最近更新 更多