javascript - 无法通过快捷方式访问 QML 中的菜单项
问题描述
这是 QtQuick.Controls.12.2 的代码。它显示正确,但是当我按 Ctrl 时没有任何反应。
我希望打印语句能够执行。我在这里做错了什么?
Menu
{
title: qsTr("File")
MenuItem
{
id: new_
text: "qqq"
onTriggered:
{
console.log("saasd")
}
action:
Action
{
shortcut: "Ctrl"
onTriggered: console.log("sad0asd")
}
contentItem:
Row
{
spacing: 70
Text
{
text: new_.text
font: menuItem.font
opacity: enabled ? 1.0 : 0.3
color: menuItem.highlighted ? "#ffffff" : "#21be2b"
}
Row
{
spacing: 5
Rectangle
{
color: "blue"; height: decoration.getHeight(15); width: height
}
Text
{
text: "Ctrl"
font: menuItem.font
opacity: enabled ? 1.0 : 0.3
color: new_.highlighted ? "#ffffff" : "#21be2b"
}
}
}
}
}
解决方案
实际上,看起来不可能使用单个修饰符(Ctrl/Shift/...)作为快捷方式值。
(见这个类似的问题)
将工作:
shortcut: "Ctrl+K" // modifier + key
shortcut: "K" // unique key
不管用:
shortcut: "Ctrl"
shortcut: "Shift"
...
一个可能的解决方法是在菜单外捕捉按键:
Item {
//...
focus: true
Keys.onPressed: {
if (event.key === Qt.Key_Control) {
console.log("sad0asd")
}
}
Menu {
// ...
}
}
推荐阅读
- reactjs - 在 Create React App 中获取平均笑话报告
- javascript - 如何在 JavaScript 中使用反射调用方法
- python - 如何使用硒(python)刷新页面直到警报不可见
- c# - 缺少 NuGet 包源
- android - Google Play Billing 4.0 launchBillingFlow() 永远不会返回,并且购买永远不会被确认
- python - mean_pressure_weighted 函数的计算
- debugging - 如何使用 .NET Core 在 GraphQL 中传递多个字段进行查询
- java - 出现登录错误。com.firebase.ui.auth.data.model.PhoneNumberVerificationRequiredException:电话号码需要验证
- c# - C# 上的 Mysql 未打开“System.InvalidOperationException:'连接必须有效且打开。'”
- postman - 我可以从 Postman 中的集合生成开放 api 吗?