PDA

View Full Version : QApplication::activeWindow always returns '0' on Mac



dpatel
13th February 2012, 11:25
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.



void ConfigurationPanel::changeEvent ( QEvent * event)
{
if(event->type() == QEvent::ActivationChange)
{
if(!isActiveWindow())
{
if(QApplication::activeWindow())
{
close();
}
}
}
}

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

dpatel
14th February 2012, 04:22
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!