Results 1 to 4 of 4

Thread: Application Lost Focus / Inactive / In Background

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application Lost Focus / Inactive / In Background

    Hi All,

    The issue i am facing is basically how do i detect my application has lost focus as a result of user doing something else maybe checking there SMS or making/receiving a call.

    All i want to do is detect this focus change and 'Pause' my app from doing any heavy calculation or simply sending a message "User Inactive State" to TCP Server.

    Regards,
    Javed

    i have tried these two solutions but none works for me, perhaps i am doing it wrong.


    Solution 1:- Does not ssems to be emitting signal when app looses focus.
    Qt Code:
    1. ProgressWin::ProgressWin(QWidget *parent) : QDialog(parent), ui(new Ui::ProgressWin)
    2. {
    3. ui->setupUi(this);
    4.  
    5. #ifdef Q_OS_SYMBIAN
    6. this->showMaximized();
    7. #else
    8. this->show();
    9. #endif
    10.  
    11. QWidget::setFocusPolicy(Qt::StrongFocus);
    12. connect(this, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(OnAppFocusChanged(QWidget*, QWidget*)));
    13. }
    14.  
    15.  
    16. void ProgressWin::OnAppFocusChanged(QWidget* old, QWidget* now)
    17. {
    18. if(NULL == old)
    19. {
    20. // do something or nothing
    21. }
    22. else if(NULL == now)
    23. {
    24. Pause(); // Pause all calculation
    25. SendTCP_UserInActive();
    26. }
    27. else
    28. {
    29. // do something or nothing
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    Solution 2 :- Does not work if user selects "Calendar key or Email Key" pressed on Nokia E52 Handset. Its a crappy solution anyway.
    Qt Code:
    1. void ProgressWin::keyPressEvent(QKeyEvent *e)
    2. {
    3. switch (e->key())
    4. {
    5. case Qt::Key_Calendar:
    6. case Qt::Key_LaunchMail:
    7. case Qt::Key_Menu:
    8. .........
    9. .........
    10. .........
    11. Pause(); // Pause all calculation
    12. SendTCP_UserInActive();
    13. break;
    14. default:
    15. // do something or nothing
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Application Lost Focus / Inactive / In Background

    try listen QWindowStateChangeEvent and check QWidget::windowState() value. There is Qt::WindowActive flag.

  3. #3
    Join Date
    Jan 2011
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application Lost Focus / Inactive / In Background

    Thanks MarekR22 for the direction. Problem solved. Much appreciated.

  4. #4
    Join Date
    Jan 2011
    Posts
    32
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Application Lost Focus / Inactive / In Background


Similar Threads

  1. Application Lost Focus / Inactive / In Background
    By javed_alam786 in forum Newbie
    Replies: 2
    Last Post: 10th May 2011, 10:08
  2. making Transparent window inactive on loose focus
    By Beena in forum Qt Programming
    Replies: 0
    Last Post: 17th November 2010, 06:01
  3. Replies: 0
    Last Post: 11th May 2010, 10:21
  4. Focus lost
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2010, 22:07
  5. How detective lost focus application ?
    By Torsten in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 14:19

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.