Results 1 to 5 of 5

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

  1. #1
    Join Date
    Jul 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to detect if a window has been minimized/Alt-Tab'd ??

    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 :

    Qt Code:
    1. bool Note::eventFilter(QObject *object, QEvent *event)
    2. {
    3. if( event->type() == QEvent::FocusOut )
    4. {
    5. Note::writeToFile();
    6. return true;
    7. }
    8.  
    9. return false;
    10. }
    To copy to clipboard, switch view to plain text mode 

    with
    Qt Code:
    1. installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 
    on the cosntructor.

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to detect if a window has been minimized/Alt-Tab'd ??

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to detect if a window has been minimized/Alt-Tab'd ??

    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.

  4. #4
    Join Date
    Jul 2014
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to detect if a window has been minimized/Alt-Tab'd ??

    The windowStateChanged worked for minimizing, but not when I just switch to another window, if it's put to background. Any ideas?

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to detect if a window has been minimized/Alt-Tab'd ??

    Try with this->isActiveWindow() to know whether your current window is active or not.

Similar Threads

  1. Detect Clicks outside QML Window
    By ustulation in forum Qt Quick
    Replies: 1
    Last Post: 18th June 2014, 12:21
  2. Detect if window is bigger than screen
    By qt_developer in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2014, 17:36
  3. Replies: 3
    Last Post: 11th October 2013, 10:19
  4. how to detect window resize event ?
    By phenoboy in forum Qt Programming
    Replies: 5
    Last Post: 17th June 2013, 04:04
  5. Mdi minimized windows always on top?
    By erikusa in forum Qt Programming
    Replies: 0
    Last Post: 18th December 2010, 00:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.