【发布时间】:2017-12-07 00:49:39
【问题描述】:
我有一个在 Debian Linux 上开发的 Qt 5 应用程序,现在我正在移植它并为 OS X 增强它。当我把它带过来时,所有的菜单快捷方式都出现在表单编辑器中。视觉快捷方式已更改以反映使用命令键而不是控制键。因此,登录操作的 ui 文件如下所示:
<action name="LoginAction">
<property name="text">
<string>Log in...</string>
</property>
<property name="shortcut">
<string>Ctrl+L</string>
</property>
</action>
但是,现在唯一可以使用的键盘快捷键是 OS X 使用的默认快捷键,例如命令-Q。
我在 Qt 论坛上看到讨论表明它与 Qt 5 将快捷方式移交给 Cocoa 有关。这篇 Keyboard shortcuts - function keys - created in Qt app don't work on OSX 的帖子提出了一个我合并的解决方法,
#if defined (Q_OS_MACX)
ui->LoginAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
ui->LoginAction->setShortcutContext(Qt::ApplicationShortcut);
#endif
但快捷方式仍然不起作用。 Command-L 不会触发 LoginAction。
感谢任何帮助。
【问题讨论】: