在Qt应用中创建的键盘快捷键-功能键-在OSX上不起作用 [英] Keyboard shortcuts - function keys - created in Qt app don't work on OSX

查看:308
本文介绍了在Qt应用中创建的键盘快捷键-功能键-在OSX上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序在主菜单中使用某些快捷方式.它适用于Windows和Linux.移植到Mac时,某些快捷方式将不起作用.

I have a program that in main menu uses certain shortcuts. It works in windows and Linux. When porting to mac, certain shortcuts will not work.

使用QT Designer创建菜单.看起来像这样

The menu is created using QT Designer. It looks like this

QAction *actDelete;
actDelete = new QAction(MainWindow);
actDelete->setObjectName(QString::fromUtf8("actDelete"));
menu_Edit->addAction(actDelete);
actDelete->setText(QApplication::translate("MainWindow", "Delete", 0, QApplication::UnicodeUTF8));
actDelete->setShortcut(QApplication::translate("MainWindow", "Del", 0, QApplication::UnicodeUTF8));


QAction *act1;
act1 = new QAction(MainWindow);
act1->setObjectName(QString::fromUtf8("act1"));
menu1->addAction(act1);
act1->setText(QApplication::translate("MainWindow", "Action 1", 0, QApplication::UnicodeUTF8));
act1->setShortcut(QApplication::translate("MainWindow", "F12", 0, QApplication::UnicodeUTF8));

唯一不起作用的键是功能键,以及Delete键(出于Delete的原因,可能是Mac已将其替换为技术上为Backspace的键...,但仍称为Delete键,因此它应该可以工作?)

The only keys that don't work are the function keys, and Delete (for Delete the reason may be that Mac has replaced it with a key that technically is backspace... but it is still called Delete so it should work ?)

其他按键组合正常工作...功能键似乎已分配给其他功能...

Other key combinations work... The function keys are assigned to other functionality it seems...

似乎不可能通过代码删除功能键的默认功能(是真的吗?)-所以我去了,然后单击按钮以启用"将所有F1,F2等键用作标准功能键."此时,我可以按功能键,查看它们生成什么代码(例如ctrl + F12cmd + F12key=0x100003B).

It seems that it is impossible to remove the default functionality of function keys through code (is that really true ?) - so I went and clicked the button to 'Enable "Use all F1, F2, etc. keys as standard function keys."'. At this point I can press the function keys and see what code they generate (like key=0x100003B for ctrl + F12 or cmd + F12).

在主窗口构造函数中,实例化ui之后,我尝试了

In the main window constructor, after instantiating ui, I tried

#if defined Q_OS_MACX
m_ui->act1->setShortcut(tr("CTRL+F12")); // still nothing happening
m_ui->act1->setShortcut(Qt::CTRL+Qt::Key_F12);  // same, no effect on mac (though if i put it for windows the ctrl+F12 does have the desired effect
#endif

Qt版本4.7-4.8,使用g ++构建的OSX 10.6.8

Qt version 4.7-4.8, OSX 10.6.8 building using g++

推荐答案

添加了Mac快捷方式的定义

Added a definition of shortcuts for Mac

#if defined (Q_OS_MACX)
    m_ui->act1->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F12));
#endif

添加了Backspace(而不是Mac的Delete).

Added Backspace instead of Delete for Mac.

这篇关于在Qt应用中创建的键盘快捷键-功能键-在OSX上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆