Q:

Respond to application-wide "hotkey" in Qt

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?
I want to use the F12 key to toggle the main window fullscreen on/off.

A:

I haven't tried, but here is what I would do :
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);

Then you just need to connect a slot to the QShortcut::activated() signal.

