在 QtQuick Shortcut 中处理修饰符 [英] Handling modifiers in QtQuick Shortcut
问题描述
我有一个简单的 QtQuick 应用程序,比如说
I have a simple QtQuick application, say
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
Shortcut {
sequence: "i"
context: Qt.ApplicationShortcut
onActivated: {
console.log("activated!")
}
}
}
当我按下I"键时,我看到已激活!"在控制台中.但我的问题是我的应用程序应该响应 Alt 键(没有任何主键).当我将序列"属性设置为Alt"(或Ctrl"、Shift"、...任何修饰符)时,没有任何反应.那么有没有办法只处理快捷方式中的修饰符按下?
When I press the "I" key i see "activated!" in the console. But my problem is my app should response to Alt key (without any main key). When I set "sequence" property to "Alt" (or "Ctrl", "Shift", ... any modifier) nothing happens. So is there any way to handle only modifier pressing within the shortcut?
我想我不能使用 Keys.onPressed 因为我想处理 Alt 键,无论现在关注哪个项目
I think I can not use Keys.onPressed because I want to handle Alt key no matter which Item is focused now
推荐答案
我认为没有办法在 Windows 上执行此操作,如果您正在测试的话.这也是我的应用程序的一个问题,用户应该能够按住 Alt 来使用颜色选择器.不过在 macOS 和 Ubuntu 上运行良好.
I don't think there is a way to do this on Windows, if that's where you're testing. It's been a problem for my application too, where the user should be able to hold Alt to use a colour picker. Works fine on macOS and Ubuntu though.
我的猜测是,它与 alt 是在 Windows 上激活菜单项的全局快捷方式有关.虽然 Ubuntu 也是如此,但它在那里运行良好.
My guess is that it has something to do with alt being a global shortcut for activating menu items on Windows.. though the same is true for Ubuntu, and it works fine there.
这似乎是一个问题,例如Windows 上的 Photoshop 也是如此,有几个常见的技巧可以解决这个问题:
It seems to be an issue for e.g. Photoshop on Windows as well, with several common hacks to work around it:
- https://superuser.com/questions/1086805/windows-10-how-to-disable-menu-bar-toggle-by-pressing-alt
- https://answers.microsoft.com/en-us/windows/forum/windows8_1-desktop/how-can-i-disable-altunderlined-letter-shortcut-in/67a6e0b1-f161-4870-b9f5-33470f1a5ddb
这篇关于在 QtQuick Shortcut 中处理修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!