Qt 虚拟键盘隐藏文本QML
我有下面的虚拟键盘,它将flickable的y设置为一个不隐藏文本的值。设置变量包含以下IntSettingsRowQt 虚拟键盘隐藏文本QML,qt,qml,virtual-keyboard,Qt,Qml,Virtual Keyboard,我有下面的虚拟键盘,它将flickable的y设置为一个不隐藏文本的值。设置变量包含以下IntSettingsRow //Administration.qml K_VirtualKeyBoard{ id: keyboard z:100 onVisibleChanged: { if(visible){ if(settings.posY - keyboard.height > 0){ flickab
//Administration.qml
K_VirtualKeyBoard{
id: keyboard
z:100
onVisibleChanged: {
if(visible){
if(settings.posY - keyboard.height > 0){
flickable.contentY = settings.posY - keyboard.height + 20
}
else{
flickable.contentY = 0
}
}
if(!visible){
settings.settingsRow.textField.focus = false
flickable.contentY = 0
}
}
}
我有一个IntSettingsRow,它是一个文本字段,用来插入一些文本
//GeneralSettings.qml
IntSettingsRow{
id: touchDeactivationTimedTime
height: itemHeight
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 8
validator: IntValidator{bottom: 10; top: 300}
title: qsTr("deactivate time")+":"
value: currentSettings?currentSettings.deactivationTime:0
onValueChanged:{
var val = parseInt(value)
if (!isNaN(val)){
currentSettings?currentSettings.deactivationTime = val:{}
}
}
onEditingFinished: {
if (value === "") textField.text = currentSettings.deactivationTime
}
onFocusChanged: {
settingsRow = touchDeactivationTimedTime
if(!textField.focus){
editingFinished()
posY = 0
}else{
posY = mapToItem(parent, x, y).y
}
}
}
不知何故,在第一次点击文本字段时,虚拟键盘会像预期的那样弹出,而flickable会移动。我把键盘藏起来,然后再试一次。它不工作。因此,虚拟键盘会弹出,但flickable不会更改。我在intsettingsrow中找到了一种直接从onfocus编辑flickable的解决方案。现在它起作用了 因此,我将我的K_VirtualKeyboard更改为:
K_VirtualKeyBoard{
id: keyboard
z:100
onVisibleChanged: {
if(!visible){
flickable.contentY = 0
}
}
}
并将其添加到触发键盘的文本字段中
textField.onReleased: {
var keyBoardY
if(keyboard.visible)
keyBoardY = keyboard.y
else
keyBoardY = keyboard.y - keyboard.height
if(keyBoardY < (mapToItem(root.parent.parent,0,0).y + height*2))
flickable.contentY = (mapToItem(root.parent.parent,0,0).y + height*2) - keyBoardY + 8
}
textField.onReleased:{
var键盘
if(键盘可见)
keyboard y=keyboard.y
其他的
keyBoardY=keyboard.y-keyboard.height
如果(键盘y<(mapToItem(root.parent.parent,0,0).y+高度*2))
flickable.contentY=(mapToItem(root.parent.parent,0,0).y+高度*2)-键盘y+8
}
请把完整的解决方案放在这里好吗?很难从您的邮件中理解。@AlekseyKontsevich有一段时间没有看到您的评论。我想已经很晚了,但如果不是的话,我更新了我的答案。希望它能帮助你或任何其他人,谁可能需要它以后在银行!别担心,我在其他主题中找到了解决方案: