Results 1 to 5 of 5

Thread: How to determine if my app is active...

  1. #1
    Join Date
    Feb 2006
    Posts
    21
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default How to determine if my app is active...

    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

  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 determine if my app is active...

    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).

  3. The following user says thank you to wysota for this useful post:

    Ben.Hines (10th March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: How to determine if my app is active...

    Use for main app win next events
    QEvent::WindowActivate - Window was activated.
    QEvent::WindowDeactivate - Window was deactivated.
    a life without programming is like an empty bottle

  5. #4
    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 determine if my app is active...

    Quote Originally Posted by zlatko
    Use for main app win next events
    Why for main window? And what if the application has more than one top level window?

  6. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: How to determine if my app is active...

    then as you said focus events must be helpfull too

    Main window..em its my miscalculation
    Last edited by zlatko; 20th February 2006 at 16:04.
    a life without programming is like an empty bottle

Similar Threads

  1. Qt application with live Active X camera feed.
    By bitChanger in forum Qt Programming
    Replies: 8
    Last Post: 4th September 2012, 19:26
  2. Rendering 3D Objects on Ubuntu
    By Sandip in forum Qt Programming
    Replies: 3
    Last Post: 19th January 2009, 14:29
  3. Problem with Painter in Qt4.4.1
    By merry in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 13:47
  4. How to determine available memory
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 00:00
  5. Painter not active!
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 30th March 2006, 15:44

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.