C++ Surface Pro平板电脑上的QML应用程序键盘行为
我使用的是Qt5.8(vs 2015 32位)。在未连接物理键盘/鼠标的Surface Pro平板电脑上运行QML应用程序时,无论我当前是否尝试键入文本框,键盘都会弹出。更改文本父级的可见性不会关闭键盘。它将在用户下次触摸应用程序时弹出。 如果应用程序处于全屏模式,则键盘会在应用程序后弹出,但键盘仍然可以单击,因此无法单击应用程序本身。 有没有关于如何按需以编程方式显示/隐藏键盘的建议 此示例代码为我生成键盘弹出窗口。如果用户单击enter或父窗口不再可见,我尝试将文本字段的焦点更改为false,但没有效果。我还尝试在父窗口不再可见时使用Qt.inputMethod.hide(),但这没有效果 main.qmlC++ Surface Pro平板电脑上的QML应用程序键盘行为,c++,qt,qml,C++,Qt,Qml,我使用的是Qt5.8(vs 2015 32位)。在未连接物理键盘/鼠标的Surface Pro平板电脑上运行QML应用程序时,无论我当前是否尝试键入文本框,键盘都会弹出。更改文本父级的可见性不会关闭键盘。它将在用户下次触摸应用程序时弹出。 如果应用程序处于全屏模式,则键盘会在应用程序后弹出,但键盘仍然可以单击,因此无法单击应用程序本身。 有没有关于如何按需以编程方式显示/隐藏键盘的建议 此示例代码为我生成键盘弹出窗口。如果用户单击enter或父窗口不再可见,我尝试将文本字段的焦点更改为false
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中,我正在收听文本更改,以查看当页面不可见且用户在键盘上键入时,文本是否发生了更改,但我没有看到任何文本更改。事实证明,文本输入不会显示键盘,因此我将改为使用它