我面临着一些我无法解释的事情...... 我有这个代码:
import QtQuick 2.12
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.12
import QtQuick.LocalStorage 2.0
import QtMultimedia 5.15
import 'JavaScript.js' as JS
ApplicationWindow {
id: mainWindow
visible: true
width: 480 height: 800
title: qsTr("application")
Item {
id: keyboardHandler
focus: true
onFocusChanged: console.log(keyboardHandler.focus);
Keys.onPressed: { console.log(event.text; }
}
Image {
id: focusToKeyboardHandler
anchors.fill: parent
MouseArea {
anchors.fill: parent
onClicked: { keyboardHandler.focus = true; }
}
}
TextField {
id: textfieldID
}
}
当我启动应用程序时,所有键盘敲击都会正确打印到控制台中,因为它们应该...... 但是,如果我单击文本字段,然后返回图像,则击键根本不会打印任何内容:( 为什么?当我单击图像时,它正确地让我将焦点集中到键盘处理程序(由 onFocusChanged 证明在我开始打字之前始终调试为 true...因此,在需要时,焦点始终集中在键盘处理程序上)...
为了确定我也尝试将此行更改为:
onClicked: { keyboardHandler.focus = true; keyboardHandler.forceActiveFocus(); }
没有运气
更新:它适用于在键盘按键上物理打字...但是使用隐藏的条形码扫描仪,它仅在我第一次启动应用程序时才起作用,而不是当我改变焦点然后返回键盘处理程序时
更新2:当关闭和打开应用程序时,仅第一次再次工作(或直到我重新更改焦点)
有什么想法可能会导致这种情况吗?
同样的问题...QT 5.11 我的 Keys.onPressed 工作正常,但编辑文本文件后它不起作用......