Handling input when application isn't in focus? (Global Input Hotkey?)

  • I want the app that I'm working on to have a bindable hotkey to hide/unhide its main Window (it actually uses a QtQuick style GUI, but this should apply to Qt in general, I think). For example, if the user sets their hide/unhide button to be Super[Meta/Windows]+Home, they should be able to hit that button combo to hide the application; when they want to use it again, they can then unhide it with the same hotkeys.

    I have a simple little hide/unhide function (slot):
    @/* Toggles application's window visibility.

    • Returns TRUE if the window exists AND is currently visible. */
      bool AppSystem::toggleLauncherVisibility(void)
      QWindow * window = QGuiApplication::topLevelWindows().front();
      if( isWindowVisible() )
      return false;
      return true;
      else return false;

    However, I've been having an obvious issue with Window 'focus'.. Once I hit the key to hide the app window, my program no longer accepts keyboard inputs so i'm not able to unhide the window. If i understand correctly, there are some things I can do with window modality to force my application to hold keyboard focus, however I don't want my application to handle all keyboard events while hidden - I just want it to be able to recognize the 'unhide' hotkey regardless of its focus state.

    How can I achieve this focus/input behavior in Qt/QtQuick/QML?

  • Lifetime Qt Champion


    You might be interested by "this":http://libqxt.bitbucket.org/doc/0.6/qxtglobalshortcut.html

    Hope it helps

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.