Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    3
    2510
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      katanaswordfish last edited by

      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'?

      1 Reply Last reply Reply Quote 0
      • K
        katanaswordfish last edited by

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

        QGuiApplication::focusWindow() [static]

        1 Reply Last reply Reply Quote 0
        • H
          Hareen Laks last edited by

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post