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. QSystemTrayIcon: Menu gets disabled if no window has focus

QSystemTrayIcon: Menu gets disabled if no window has focus

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 822 Views 2 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.
  • V Offline
    V Offline
    vic.ju
    wrote on last edited by
    #1

    Hello,

    I encountered a problem with the QSystemTrayIcon and don't know why it behaves like it does.

    My mac application is an agent (LSUIElement=true in info.plist) and displays a QSystemTrayIcon at all time. When I click the tray icon and the app is not the active app, all actions in the displayed QMenu are disabled. I checked, if my actions are disabled or if the menu is disabled, but non of them are.

    Does anyone have an idea what is getting disabled and how I can prevent that?

    Thanks!

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

      Hi and welcome to devnet,

      Which version of Qt ?
      Which version of macOS ?
      Can you provide a minimal compilable example that shows that behaviour ?

      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
      • V Offline
        V Offline
        vic.ju
        wrote on last edited by
        #3

        I'm using macOS 10.15.6 and Qt 5.14.2.

        I've built a basic demo app, but unfortunately it is working completely normal. Seems to be a problem inside of my implementation. I will strip down my application to find the error or provide a malfunctioning app if it still appears.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vic.ju
          wrote on last edited by vic.ju
          #4

          I found what's causing the issue. I have a custom NSApplicationDelegate that is somehow interfering. The only thing that I implemented for the delegate are

          - (BOOL)applicationShouldHandleReopen:(NSApplication*)sender hasVisibleWindows:(BOOL)flag;
          - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
          

          Maybe I need to implement some other features? I have another application that also use a NSApplicationDelegate and it is working fine.

          Edit:
          I uploaded the demo app to my google drive: TrayIconTest.zip

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vic.ju
            wrote on last edited by
            #5

            I found the reason for the problem. I set the NSApplicationDelegate after I created the QApplication and this confuses the application (firstResponder). So the solution is to just set it before.

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

              Glad you found out and thanks for sharing the solution.

              Out of curiosity, are you using applicationShouldTerminate to avoid the application to end while the system tray icon stays alive ? If so, it's not needed, Qt already provides quitOnLastWindowClosed for that kind of use cases.

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

              V 1 Reply Last reply
              0
              • SGaistS SGaist

                Glad you found out and thanks for sharing the solution.

                Out of curiosity, are you using applicationShouldTerminate to avoid the application to end while the system tray icon stays alive ? If so, it's not needed, Qt already provides quitOnLastWindowClosed for that kind of use cases.

                V Offline
                V Offline
                vic.ju
                wrote on last edited by
                #7

                @SGaist
                I use the quitOnLastWindowClosed function for that as you stated. I use applicationShouldTerminate to call the correct cleanup methods on application exit. I'm not sure why we do it this way, but there were some problems in the past when exiting the application.

                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