QML键盘响应(QML keyboard response)

1、代码

Item {
    focus: true
    Keys.onPressed:
    {
        console.log(event.key)
        switch(event.key)
        {

        case Qt.Key_U:

            break;
        case Qt.Key_M:
            Qt.quit();
            break;
        }
    }
}    

必须设置父Item的焦点为true,否则接收不到按键信号

————————

1. Code

Item {
    focus: true
    Keys.onPressed:
    {
        console.log(event.key)
        switch(event.key)
        {

        case Qt.Key_U:

            break;
        case Qt.Key_M:
            Qt.quit();
            break;
        }
    }
}    

The focus of the parent item must be set to true, otherwise the key signal will not be received