响应应用程序范围内的“热键".在Qt中 [英] Respond to application-wide "hotkey" in Qt
本文介绍了响应应用程序范围内的“热键".在Qt中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的Qt应用程序,我只想响应 F12 键,而不管哪个窗口小部件具有焦点.
I've got a simple Qt app, and I just want to respond to the F12 key, regardless of which widget has focus.
是否有一些简单的信号或可以挂接到的东西?
Is there some easy signal or something I can hook in to?
我想使用 F12 键在全屏状态下打开/关闭主窗口.
I want to use the F12 key to toggle the main window fullscreen on/off.
推荐答案
我没有尝试过,但这是我会做的事情:
I haven't tried, but here is what I would do :
创建一个 Q快捷方式,并确保其
Create a QShortcut and make sure its context (with setContext()
) is Qt::ApplicationShortcut
.
shortcut = new QShortcut(QKeySequence(Qt::Key_F12), parent);
shortcut->setContext(Qt::ApplicationShortcut);
然后,您只需要将插槽连接到 QShortcut :: activated ()信号.
Then you just need to connect a slot to the QShortcut::activated() signal.
这篇关于响应应用程序范围内的“热键".在Qt中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文