Qt: how to apply a shortcut( Key_Comma + Key_Return) to action

断了今生、忘了曾经 提交于 2019-12-02 14:06:50

问题


I tried to set a shortcut by the following code, but it doesn't work. If I change it to ALT + Comma or ALT + Return, it will be fine. but the request is Comma + Return. Does anyone know how to set this special shortcut on Qt?

    @shotcut = Qt::Shortcut.new(Qt::KeySequence.new(Qt::Key_Comma + 
    Qt::Key_Return), self, SLOT('save_by_shortcut()'))
    @shotcut.setEnabled(true)

Any help would be appreciated!


回答1:


You can create it by using the multiple arguments constructor for QKeySequence.

like this:

auto ac = new QAction(this);
ac->setShortcut(Qt::Key_Comma + Qt::Key_Return);


来源:https://stackoverflow.com/questions/45729495/qt-how-to-apply-a-shortcut-key-comma-key-return-to-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!