【发布时间】:2016-02-10 06:38:57
【问题描述】:
在 QML 中,当我使用 Menu QML 类型时,event.modifiers 在 Keys.onPressed 中不起作用,但在注释 Menu 类型后它起作用了。我究竟做错了什么?是否有与 Menu QML 类型相关的错误? 我正在使用 Qt 5.4.0。
Rectangle {
id: main
width: 600
height: 300
Menu {
id: menu
title: "Edit";
MenuItem { text: "Copy";shortcut: "Ctrl+C" }
MenuItem { text: "Paste";shortcut: "Ctrl+V" }
MenuItem { text: "Select" }
MenuItem { text: "Select all";shortcut: "Ctrl+A" }
MenuSeparator { }
MenuItem { text: "Delete";shortcut: "Delete" }
MenuItem { text: "Delete all" }
MenuSeparator { }
MenuItem { text: "Auto arrange" }
}
Keys.onPressed: {
if((event.key === Qt.Key_C) && (event.modifiers & Qt.ControlModifier))
{
console.log("Ctrl+C is pressed")
}
}
MouseArea{
anchors.fill : parent;
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
main.focus = true;
if(mouse.button === Qt.RightButton){
menu.popup();
}
}
}
}
【问题讨论】: