View Full Version : How to determine if my app is active...

20th February 2006, 16:23

I would like to be able to determine if my Qt application is the 'current' application. E.g. on Windows XP and MacOS, there is one application that is considered to be the 'current' one. I thought that detecting events with type equal to QEvent::ApplicationActivated or QEvent::ApplicationDeactivated would be the correct way to detect this change. I overrode QApplication::event(QEvent *e) and put in cases for the two types mentioned above, but these two events do not seem to be received (at least on Windows XP). Does anyone know how to detect that the application has become active or inactive?


20th February 2006, 16:33
QApplication::activeWindow() and QApplication::focusWidget(). If they both return 0, none of the applications windows is active, hence the application does not have focus (in your terms -- is not the "current" one).

20th February 2006, 16:35
Use for main app win next events

QEvent::WindowActivate - Window was activated.
QEvent::WindowDeactivate - Window was deactivated.

20th February 2006, 16:38
Use for main app win next events

Why for main window? And what if the application has more than one top level window?

20th February 2006, 17:02
then as you said focus events must be helpfull too :)

Main window..em its my miscalculation :o