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

SystemTrayIcon remains pressed if menu is opened from onActivated handler

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.3
    • Quick: Other
    • None
    • macOS Sonoma 14.5
      Qt 6.5.3
    • macOS

    Description

      SystemTrayIcon has menu property. Which is great, but in many cases desired behavior is to activate app on left click and to open menu on right click. Which is impossible using this property, menu opens always out of the box.

      However, onActivated handler can be used to detect right click, and to open menu. And here comes the issue. SystemTrayIcon remains in pressed state.

      Run attached code.
      Right click tray icon
      Select any menu option
      Observe tray icon. It gots stuck in pressed state.

      import QtQuick
      import QtQuick.Controls
      import Qt.labs.platform
      
      Window {
          id: window
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          SystemTrayIcon {
              visible: true
              icon.source: ":/icon.png"
              icon.mask: true
      
              onActivated: function(reason) {
                  if (reason === SystemTrayIcon.Context) {
                      menu.open()
                  } else {
                      window.show()
                      window.raise()
                      window.requestActivate()
                  }
              }
          }
      
          Menu {
              id: menu
              MenuItem {
                  text: "menu item 1"
                  onTriggered: {
                      window.show()
                      window.raise()
                      window.requestActivate()
                  }
              }
              MenuItem {
                  text: "menu item 2"
              }
          }
      }
      

      Attachments

        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
            sergei.nevdakh Sergei Nevdakh
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes