原文出处:http://qt-project.org/forums/viewthread/720
Hello,
I’m building a desktop application using Qt 4.6.2 for both Mac and Windows.
I wanted to implement some Mac specific behavior:
When you click the Close button in the main application window, the application window should close but it shouldn’t quit.
-> I’ve got this part working
When you click on the application dock icon, the application window should be shown and brought to the front.
-> I’m able to get this to work as long as some other application is the active application. If my application is still the active app, then clicking on the dock icon has no effect.
Can anyone help me with this problem?
Thanks,
Priyanka
I know it is an old thread but here is a workaround that seems to be OK:
-
void MainWindow :: closeEvent ( QCloseEvent *event )
-
{
-
#ifdef __MACOSX_CORE__
-
if (event -> spontaneous ( ) )
-
{
-
QStringList args ;
-
args << "-e" ;
-
args << "tell application \"System Events\"" ;
-
args << "-e" ;
-
args << "set visible of process\"" + QFileInfo ( QApplication :: applicationFilePath ( ) ). baseName ( ) + "\" to false" ;
-
args << "-e" ;
-
args << "end tell" ;
-
QProcess :: execute ( "osascript" , args ) ;
-
event -> ignore ( ) ;
-
return ;
-
}
-
#endif
-
//Do quit stuff
-
}
I would have guessed spontaneous() should work the other way around…