【发布时间】:2015-01-08 02:37:09
【问题描述】:
有没有办法处理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;
}
}
【问题讨论】:
标签: qt event-handling window key qml