Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-98504

QSystemTrayIcon example: selecting Quit from context menu shows unnecessary message

    XMLWordPrintable

Details

    • 46cadf7b48288fce4de6147ae38de493354c23d0 (qt/qtbase/dev) 84911c30d4546500d1ef6bf7e9251125b0fce3d4 (qt/qtbase/6.2)

    Description

      It shows the QMessageBox:

      The program will keep running in the system tray. To terminate the program, choose Quit in the context menu of the system tray entry.

      even though I'm doing what it says, to terminate by selecting Quit on the context menu.

      Tested with xfce4-panel's version of the tray, which is a D-Bus system tray (which conveniently can run on a plain X11 session without a full desktop environment like KDE or Gnome).

      And it turns out that in this case the QCloseEvent is not spontaneous, so we can easily avoid it with the same code that so far was needed only on macOS:

      //! [2]
      void Window::closeEvent(QCloseEvent *event)
      {
      #ifdef Q_OS_MACOS
          if (!event->spontaneous() || !isVisible()) {
              return;
          }
      #endif
          if (trayIcon->isVisible()) {
              QMessageBox::information(this, tr("Systray"),
                                       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."));
              hide();
              event->ignore();
          }
      }
      //! [2] 

      This needs testing on all the platforms to see if they're all consistent now, apparently.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              srutledg Shawn Rutledge
              srutledg Shawn Rutledge
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes