PDA

View Full Version : How to detect if a window has been minimized/Alt-Tab'd ??



lgos
29th July 2014, 22:27
Hi,

The title says it all. I want to do something evverytime my window is minimized, or put to background, everytime I switch to other window.
I thought it had to do with losing focus so I tried :



bool Note::eventFilter(QObject *object, QEvent *event)
{
if( event->type() == QEvent::FocusOut )
{
Note::writeToFile();
return true;
}

return false;
}


with
installEventFilter(this); on the cosntructor.

But it didn't work. It works with QEvent::KeyPress however.

wysota
29th July 2014, 22:37
In Qt5 there is a windowStateChanged signal in QWindow class and applicationStateChanged signal in QGuiApplication. I don't remember if there are equivalent signals in Qt4.

ChrisW67
29th July 2014, 22:39
The eventFilter() is really designed for monitoring and dealing with the events of another QObject (as in the docs example). There are dedicated (protected) handlers for the focus out, hide and show events of this object that should be useful.

lgos
29th July 2014, 23:22
The windowStateChanged worked for minimizing, but not when I just switch to another window, if it's put to background. Any ideas?

Gokulnathvc
19th September 2014, 08:45
Try with this->isActiveWindow() to know whether your current window is active or not.