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

QSystemTrayIcon - unable to reset context menu

    XMLWordPrintable

Details

    • macOS
    • c1d389a13 (dev), 8fcd3b1b1 (6.6), 350025e93 (tqtc/lts-6.5)

    Description

      See simple example TrayIconTestMacBug.zip

      #include "mainwindow.h"
      #include "./ui_mainwindow.h"
      
      #include <QSystemTrayIcon>
      #include <QMenu>
      #include <QPushButton>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          trayMenu = new QMenu(this);
          trayMenu->addAction(tr("Quit"), qApp, &QCoreApplication::quit);
      
          trayIcon = new QSystemTrayIcon(QPixmap(":/banana.png"), this);
          trayIcon->setContextMenu(trayMenu);
      
          trayIcon->show();
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::on_pushButton_clicked()
      {
          if (trayIcon->contextMenu()) {
              trayIcon->setContextMenu(nullptr);
              ui->pushButton->setText("Add Tray Menu");
          } else {
              trayIcon->setContextMenu(trayMenu);
              ui->pushButton->setText("Remove Tray Menu");
          }
      }
      

      trayIcon->setContextMenu(nullptr) has no effect.

      Just launch it and click on tray icon (Banana) - menu is displayed - OK
      Press on 'Remove Tray Menu' button and click on tray icon again - menu is still displayed - BUG.

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              studiosus Vladimir Belyavsky
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes