Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSystemTrayIcon OSX questions
Forum Updated to NodeBB v4.3 + New Features

QSystemTrayIcon OSX questions

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 16.7k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jdarnold
    wrote on last edited by
    #5

    Sorry, that's what I meant - a single (or even double) left click on OS X Dock icon for my app doesn't bring it back up. If I select quit from the right click menu, it goes away, so there is something going on.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #6

      That's strange, as it is something that is handled by OS X itself. How does your app go out of focus? Do you hide the window (with Cmd-H) or do you close it (with Cmd-W)? If it is hidden, it should reappear. If it is closed, it can be that the application itself still runs, but has no window to show. Does the menu on the top of the screen change, when you left-click the icon in the dock? If yes, then your application is active but has no windows to show, if no something strange is going on.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jdarnold
        wrote on last edited by
        #7

        I click the Close button on the app window, which I thought by default just hides a window (like it does on Windows). But maybe it actually closes the window? If I select "Hide" from the right click dock menu, it works fine. Do I need to do something special in order to not close the window on the Mac?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jdarnold
          wrote on last edited by
          #8

          No, I take that back. The window handles the close event thusly:

          @void visimeet::closeEvent(QCloseEvent* event)
          {
          if (trayIcon->isVisible() && !qApp->closingDown()) {
          if ( trayWarning )
          {
          QMessageBox::information(this, tr("Visimeet"),
          tr("The program will keep running in the "
          "system tray. To terminate the program, "
          "choose <b>Quit</b> in the context menu "
          "of the system tray entry."));
          trayWarning = false;
          }

              hide();
              event->ignore();
          }
          

          }
          @

          And I get the warning message and the window goes away.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #9

            There seems to be a difference if the window is hidden programmatically with hide() or by the window system with Cmd-H. In the first case the window is hidden permanently and can only be restored with calling show() again, whereas in the second case the window can be restored by clicking on the dock icon.

            You can achieve a similar behaviour if you call showMinimized() instead of hide(). In this case you get an additional icon in the dock for the hidden window (in addition to the application's icon).

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jdarnold
              wrote on last edited by
              #10

              That's not really all that great though. That means that close & minimize work the same. It certainly isn't a desired behavior on Windows, as it stays in the task bar. Is this a Qt bug or can programs not hide themselves on the Mac?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #11

                Programs can hide themselves on the mac, just use hide(). The only drawback of this method is that they cannot be restored using the dock.

                You can of course add a menu to the dock icon, and in the slots, that menu is connected to, you can redisplay the window by calling show().

                How to do this in detail depends on your application design: do you have multiple main windows of the same type, multiple main windows of different types that can only be instantiated once, only one main window, etc.? This influences how and where the dock menu is populated and its actions are executed.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jdarnold
                  wrote on last edited by
                  #12

                  We just have a single main window. Guess I'm confused about the different places for where the icon shows up on the Mac.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #13

                    Do you have a screenshot to illustrate what's drivin' you crazy?

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jolson
                      wrote on last edited by
                      #14

                      I had a similar problem. I solved it by instead of calling hide() when the user clicks x (see tray sample) we call

                      ProcessSerialNumber pn;
                      GetFrontProcess (&pn);
                      ShowHideProcess(&pn,false);

                      Now the window is closed and clicking on the dock icon works as expected.

                      1 Reply Last reply
                      0
                      • G goetz

                        On Mac OS X, the tray is usually the area in the top right corner of the main screen.

                        The tray in OS X does not support min/max/hide functions, but provides a menu to common functions, that should be available, even when the app is not in the foreground (such as setting the status in some instant messaging program or something like that).

                        Bringing the application to the forground/minimizing/maximizing is done in the Dock on the mac (the collection of icons, usually on the bottom of the main screen).

                        This is a sample code that works for me:

                        @
                        QSystemTrayIcon *sti = new QSystemTrayIcon(this);

                        QIcon xmediaIcon("/path/to/your/icon");
                        sti->setIcon(xmediaIcon);
                        sti->setVisible(true);

                        QMenu *stiMenu = new QMenu(this);
                        sti->setContextMenu(stiMenu);

                        QAction *a1 = new QAction("tray menu item 1", this);
                        stiMenu->addAction(a1);
                        connect(a1, SIGNAL(triggered()), this, SLOT(action1Fired()));

                        QAction *a2 = new QAction("tray menu item 2", this);
                        stiMenu->addAction(a2);
                        connect(a2, SIGNAL(triggered()), this, SLOT(action2Fired()));
                        @

                        D Offline
                        D Offline
                        Dev-A7med
                        wrote on last edited by
                        #15

                        @goetz hi, I know this topic is old but i have problem with macos when qsysteemtrayicon->showmessage().
                        Icon appear in top menu but notification message disappear. Dose any permission or something thing in macos to show notification message because window work fine.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved