Surface Pro Tablet上的QML应用程序键盘行为

kmx78

我正在使用Qt 5.8(vs 2015 32 bit)。在未连接物理键盘/鼠标的Surface Pro平板电脑上运行QML应用程序时,无论我当前是否在尝试输入文本框,键盘都会弹出。更改文本父级的可见性不会关闭键盘。下次用户触摸应用程序时,它将弹出。如果应用程序处于全屏模式,则键盘会在应用程序后面弹出,但键盘仍可单击,从而无法单击应用程序本身。有什么建议如何按需编程显示/隐藏键盘?

此示例代码为我生成了键盘弹出窗口。我曾尝试将文本字段的焦点更改为false(如果用户单击Enter或父窗口不再可见,但这无效)。当父窗口不再可见时,我也尝试使用Qt.inputMethod.hide(),但这无效。

main.qml

import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    property bool showPage1: false

    MyPage1 {
        id: page1
        visible: showPage1
        width: 1/2 * parent.width
        height: parent.height /3
        anchors.left: parent.left
        Rectangle {
            width: 50
            height: 50
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            anchors.margins: 10
            color: "yellow"
            MouseArea {
                anchors.fill: parent
                onClicked: console.log("page 1 corner clicked")
            }
        }


    }

    Rectangle {
        width: 50
        height: 50
        color: "blue"
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.margins: 10
        MouseArea {
            anchors.fill: parent
            onClicked: {
                showPage1 = !showPage1
            }
        }
    }
}

MyPage1.qml

import QtQuick.Controls 1.1


Rectangle {
    id: page1Root
    color: "pink"
    border.color: "red"
    border.width: 4
    anchors.fill: parent

    Text {
        text: "Page 1!"
        anchors.fill: parent

        anchors.top: parent.top
        anchors.topMargin: 10
        width: parent.width * 3/4
        height: 30
        horizontalAlignment: Text.AlignHCenter
    }

    TextField {
        id: myTextField
        width: parent.width * 3/4
        height: 50
        anchors.centerIn: parent
        text: "type something here"
        onTextChanged: {
            console.log("text changed to: " + text)
        }
        horizontalAlignment: TextEdit.AlignLeft
        verticalAlignment: TextEdit.AlignVCenter
        font.pixelSize: 22
//        Keys.onReturnPressed: {
//            focus = false
////            Qt.inputMethod.hide()
//        }
        onFocusChanged: console.log("focus changed: " + focus)
//        MouseArea {
//            anchors.fill: parent
//            onClicked: {
//                console.log("text field clicked!")
//                focus = true
//            }
//        }
    }

    onVisibleChanged: {
        console.log("page 1 root visible: " + visible)
        if (visible)
        {
            myTextField.forceActiveFocus()
        }
        else
        {
            myTextField.focus = false
//            Qt.inputMethod.hide()
        }
    }
}

在MyPage1.qml中,我正在侦听文本更改,以查看页面不可见以及键盘上的用户类型是否更改了文本,但没有看到任何文本更改。

kmx78

事实证明TextInput不会调出键盘,因此我将使用它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

想要为Surface Pro Tablet编写应用程序

在Surface Pro 2和Surface Pro 3设备上运行基于Windows RT的应用程序

我的Surface Pro 2键盘表现异常

Surface Pro 4上的Windows Hello问题

Surface Pro 3上的Ubuntu还是Linux?

Surface(Pro)软键盘+硬件键盘问题

13.10砖Surface Pro?

Surface Pro 2键盘盖在Ubuntu中不起作用

Surface Pro 4键盘无响应且LED不工作

是否可以更改通过Surface Pro 3的笔按钮打开的应用程序?

在 Microsoft Surface Pro 5 上安装 ubuntu 18.04

如何在Surface Pro 2 Ubuntu 14.04上修复wifi

在网页上获取Surface Pro 3的高度

在Surface Pro平板电脑上启用jQuery UI拖放

Surface Pro 4上的默认网络是环回

在Surface Pro上安装Ubuntu时遇到问题

Surface Pro 4在Ubuntu 18.04上不会唤醒

运行Windows 10 Pro的Surface Pro 2上的Hyper-V网络问题

双启动Surface Pro与Ubuntu?

既然“触控板设置”应用程序不可用,如何启用/禁用Windows 8 Surface Pro的触控板?

Surface Pro 3是否运行Visual Studio,SQL Server,Xampp和其他开发应用程序?

如何在Surface Pro 4(触摸)键盘上启用麦克风?

禁用Surface Pro 4 Type Cover Fn键切换行为

Microsoft Surface Pro(2017)在Type Cover上重新映射音量上/下键

Surface 2和Surface Pro 2之间的区别

在Surface Pro 3上安装Ubuntu后无法获取grub / boot

如何在Surface Pro 3(带有扩展坞)上设置外接显示器?

Request.Browser.Version是否在Surface Pro上为IE返回7?

如果我在Surface Pro上使用恢复映像,是否会删除文件?