有什么方法可以处理QtQuick.Controls
组件的ApplicationWindow中的按键事件吗? Qt5.3的文档没有提供任何方法来执行此操作。另外,它说Keys
仅存在于Item
-objects中。当我尝试处理按键事件时,它说“无法将Keys属性附加到:ApplicationWindow_QMLTYPE_16(0x31ab890)不是项目”:
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.1
import QtQuick.Window 2.1
ApplicationWindow {
id: mainWindow
visible: true
width: 720
height: 405
flags: Qt.FramelessWindowHint
title: qsTr("test")
x: (Screen.width - width) / 2
y: (Screen.height - height) / 2
TextField {
id: textField
x: 0
y: 0
width: 277
height: 27
placeholderText: qsTr("test...")
}
Keys.onEscapePressed: {
mainWindow.close()
event.accepted = true;
}
}
最佳答案
ApplicationWindow {
id: mainWindow
Item {
focus: true
Keys.onEscapePressed: {
mainWindow.close()
event.accepted = true;
}
TextField {}
}
}
关于qt - QML2 ApplicationWindow按键处理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26866710/