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

Windows of QSystemTrayIcon Driven App Do not Show in Foreground

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • 5.4.0
    • 5.3.1
    • QPA
    • None
    • macOS

      Expected behavior:

      When an OS X application who's primary interface is a QSystemTrayIcon (with no main windows) spawns a main window from the tray, it show show up in the foreground

      Observed behavior:

      The window shows up behind the window that was last active before clicking the system tray (does not happen after immediately starting the app unless you click another apps main window between start and clicking the system tray icon).

      Test case:

      main.cpp
      #include <QApplication>
      #include <QSystemTrayIcon>
      #include <QMainWindow>
      #include <QStyle>
      #include <QMenu>
      #include <QAction>
      
      
      class WindowShower : public QObject {
          Q_OBJECT
      public:
          WindowShower(QObject *parent = 0) : QObject(parent) {}
      public slots:
          void show() { (new QWidget())->show(); } // same behavior with QMainWindow
      };
      
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          a.setQuitOnLastWindowClosed(false);
      
          QSystemTrayIcon tray;
      
          QMenu * menu = new QMenu;
          tray.setContextMenu(menu);
          QAction *showWin = menu->addAction("Show Window");
          QAction *quit = menu->addAction("Quit");
          tray.setIcon(a.style()->standardIcon(QStyle::SP_ComputerIcon));
          tray.show();
      
          WindowShower w;
      
          QObject::connect(showWin, SIGNAL(triggered()),
                           &w, SLOT(show()));
          QObject::connect(quit, SIGNAL(triggered()),
                           &a, SLOT(quit()));
      
      
          return a.exec();
      }
      
      #include "main.moc"
      

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

            tpochep Timur Pocheptsov
            danimo Daniel Molkentin
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes