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. SystemTrayIcon context menu doesn't want to hide - properly implemented Tray Icon
Forum Updated to NodeBB v4.3 + New Features

SystemTrayIcon context menu doesn't want to hide - properly implemented Tray Icon

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 736 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
    Ice_trooper
    wrote on last edited by Ice_trooper
    #1

    Has someone got properly implemented System Tray Icon in qml components?
    There is a lack of information about it on forums. I almost got it, but I can't hide context Menu for that icon when user clicks away. However, showing menu works. Can you help me?
    I tried both QSystemTrayIcon registered as QML component and SystemTrayIcon from Qt.labs.platform. Both don't work.

    I will post Labs solution because QSystemTrayIcon is almost the same code in qml:

    import QtQuick 2.14
    import Qt.labs.platform 1.1
    import QtQuick.Window 2.0
    
    Item {
        property var mainAppWindowRef;
    
        SystemTrayIcon {
            visible: true;
            icon.source: "qrc:/graphics/icon.ico";
    
            onActivated: {
                if(reason === SystemTrayIcon.Context) {
    //                trayMenu.popup();
                }
                else {
                    if(applicationWindow.visibility === Window.Hidden ||
                        applicationWindow.visibility === Window.Minimized) {
                        applicationWindow.show();
                    }
                    else {
                        applicationWindow.hide();
                    }
                }
            }
    
            menu: Menu {
                id: trayMenu;
    
                MenuItem {
                    id: showGridMenuItem;
                    text: qsTr("Show grid")
                    checkable: true;
                    onTriggered: {
                    }
                }
    
                MenuItem {
                    id: openWindowMenuItem;
                    text: qsTr("Open window")
                    onTriggered: {
                        applicationWindow.show()
                    }
                }
    
                MenuSeparator { }
    
                MenuItem {
                    id: exitMenuItem;
                    text: qsTr("Exit")
                    onTriggered: {
                        systemTray.hide();
                        Qt.quit();
                    }
                }
            }
        }
    
        Connections {
            target: mainAppWindowRef;
            onClosing: {
                console.log("send to system tray...")
                close.accepted = false;
                applicationWindow.hide();
            }
        }
    }
    

    I also found a bug in reports looks like my problem: https://bugreports.qt.io/browse/QTBUG-70039?jql=text ~ "SystemTrayIcon"
    However apps like Steam or Spotify (based on Qt) got properly working system tray icon. How did their menu work and mine not?

    1 Reply Last reply
    1
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What version of Qt are you using ?
      On what OS ?
      Can you provide a complete minimal compilable example that shows that behavior ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi, now I use Qt 5.14.1 MSVC 2017 x64 and I checked that Qt 5.12.0 MSVC 2017 x64 also doesn't work.
        It's Windows 10.

        No problem, I got project on github you can try to run:
        https://github.com/IceTrooper/smart-user

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dennisf
          wrote on last edited by
          #4

          Any update on this? I have the same problem

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vanquoc12b4
            wrote on last edited by
            #5

            Hi, I tried to follow this video, and the problem solved: https://www.youtube.com/watch?v=WbDRtK1melU

            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