Results 1 to 2 of 2

Thread: QApplication::activeWindow always returns '0' on Mac

  1. #1
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QApplication::activeWindow always returns '0' on Mac

    I have an application on which I show configuration panel (QFrame) to setup the configuration. Now I want to implement functionality where I close the configuration panel if the user clicks anywhere else on my application, but if the user clicks anywhere outside the application, it should not close the application.

    Currently I have the following code which works fine on Win 7 but has issues on Mac.

    Qt Code:
    1. void ConfigurationPanel::changeEvent ( QEvent * event)
    2. {
    3. if(event->type() == QEvent::ActivationChange)
    4. {
    5. if(!isActiveWindow())
    6. {
    7. if(QApplication::activeWindow())
    8. {
    9. close();
    10. }
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    On windows QApplication::activeWindows() returns non-zero value if we click anywhere on the application (but outside configuration panel) and zero value if I click on any other application which is what is expected. But on Mac I always get zero value from QApplication::activeWindow() no matter where I click.

    Can anyone tell me how can I fix this issue?

    Thanks

  2. #2
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QApplication::activeWindow always returns '0' on Mac

    I found the solution to the issue. This is only for Mac since on windows it works fine.

    In changeEvent() handler, I post a custom event which I handle in the ConfigPanel itself. In customEvent() handler when I do QApplication::activeWindow() I get appropriate values according to the application that was clicked.

    For some reason on Mac in the changeEvent handler we always get '0' as active window.

    Hope this is helpful to others!

Similar Threads

  1. Replies: 2
    Last Post: 1st August 2011, 07:30
  2. Replies: 5
    Last Post: 1st April 2011, 11:29
  3. activeWindow control problem
    By batileon in forum Newbie
    Replies: 3
    Last Post: 17th October 2008, 08:44
  4. ActiveWindow changes after closing QFileDialog
    By mischi in forum Qt Programming
    Replies: 3
    Last Post: 13th July 2006, 13:45
  5. <QtGui/QApplication> vs. <QApplication>
    By seneca in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 11:58

Tags for this Thread

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.