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. Qt QSystemTrayIcon creates an empty new window
Forum Updated to NodeBB v4.3 + New Features

Qt QSystemTrayIcon creates an empty new window

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 4.4k 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.
  • I Offline
    I Offline
    Itehnological
    wrote on last edited by
    #1

    I working on a QtQuick 2 application and I tried to add a system tray icon.

    The problem is that when I run the following code

    @ tray = new QSystemTrayIcon(QIcon("qml/assets/icon.ico"));
    tray->show();@

    This creates an empty new window [i can tell that by the taskbar]. When I close the window the tray icon disappears too.

    How to avoid showing this additional window?

    P.S. I tried using QPlatformTrayIcon, but when I try to include it, I get the no such file or directory error.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      master of disaster
      wrote on last edited by
      #2

      show() is not the function to use here because it creates a new window, as you already noticed.

      To make the icon visible in the tray bar, use this function instead:

      @
      tray = new QSystemTrayIcon(QIcon("qml/assets/icon.ico")); //Same as above

      tray->setVisible(true);
      @

      Now you should see the icon appearing in the tray bar. But you have to make it invisible when the program quits, too:

      @
      your_class::~your_class() //Destructor
      {
      ...
      tray->setVisible(false);
      }
      @

      It would work without this code, too, but without this code, the icon would stay in the tray bar until you move the mouse over it. Then, Windows will notice that the program is closed and remove the icon, and that is confusing. I don't know whether the problem also consists on other platforms or not.

      To show a speech bubble, use this function:

      @
      tray->showMessage("Title", "message", QSystemTrayIcon::Information, 10000);
      @

      The first parameter specifies the title and the second one the message. The third one is the icon that should be shown, and the last one is the time how long the speech bubble should be shown.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Itehnological
        wrote on last edited by
        #3

        I tested your solution and it still adds an additional window.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          Be sure you set a parent window when you create the QSystemTrayIcon object.

          QSystemTrayIcon is implemented as a Shell Notification Icon, which needs a valid window handle:

          • http://msdn.microsoft.com/de-de/library/windows/desktop/bb762159(v=vs.85).aspx
          • http://msdn.microsoft.com/de-de/library/windows/desktop/bb773352(v=vs.85).aspx

          (I guess Qt will create a dummy window, if you didn't set a valid parent in the constructor)

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Itehnological
            wrote on last edited by
            #5

            How would I do that if my application uses Qt Quick 2 which is a QWindow based instead of QWidget based?

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Ian Monroe
              wrote on last edited by
              #6

              I'm having this problem as well, the ghost window shows up on Gnome 3. Using setVisible vs show() doesn't matter (as it shouldn't...). I did pass a widget as a parent to the object, but I doubt this matters either.

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Ian Monroe
                wrote on last edited by
                #7

                Here's the bug https://bugreports.qt-project.org/browse/QTBUG-30079

                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