PDA

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



Ben.Hines
20th February 2006, 15:23
Hello,

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?

Thanks,
Ben

wysota
20th February 2006, 15: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).

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


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

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

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

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

Main window..em its my miscalculation :o