How can I check if my application's Window is currently in 'focus'?



  • I have a QGuiApplication with a single top-level window which is able to be controlled using game controller inputs. It's working fine, but I've been having an issue where my application is accepting/processing controller inputs while a different application is 'in focus'. To avoid this, I want to wrap my processEvents() in a conditional statement that first checks if the applications main window is currently in focus; if it isn't the currently 'active' or 'focused' window, both the keyboard and gamepad events will be ignored.

    So, whats the best way to check if your applications window is 'in focus'?



  • Actually, nevermind. After combing through the QGuiApplication class documentation a second time I found what I was looking for.

    QGuiApplication::focusWindow() [static]



  • As I understand your question you need "hasFocus()":http://qt-project.org/doc/qt-4.8/qwidget.html#focus-prop. isn't it?


Log in to reply
 

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