Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Clicking the dock icon to show the app on Mac

    General and Desktop
    2
    2
    4410
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      Priyanka last edited by

      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

      1 Reply Last reply Reply Quote 0
      • V
        vemod last edited by

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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post