Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Shortcuts for SysTrayIcon

Shortcuts for SysTrayIcon

Scheduled Pinned Locked Moved Unsolved Qt for Python
8 Posts 2 Posters 1.3k 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.
  • J Offline
    J Offline
    joac
    wrote on last edited by
    #1

    Hi

    How do I add shortcuts (e.g. CTRL+SHIFT+C) to an application running exclusively as a SysTrayIcon? The shortcut would call a function currently called through the SysTrayIcon's QMenu. This post https://forum.qt.io/topic/18108/systray-and-keyboard-shortcuts describes a similar use-case, though the answer is not immediately helpful.

    Any assistance would be greatly appreciated!

    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,

      So you would like something like a global shortcut that can be called from anywhere and make your application react ?

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

      J 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        So you would like something like a global shortcut that can be called from anywhere and make your application react ?

        J Offline
        J Offline
        joac
        wrote on last edited by
        #3

        @SGaist said in Shortcuts for SysTrayIcon:

        Hi and welcome to devnet,

        So you would like something like a global shortcut that can be called from anywhere and make your application react ?

        Hi there, thank you, and yes!

        The idea is to have the application sit as a tray icon, and then only react after the user calls a shortcut (or right-click the icon and choose something from the menu).

        Thanks!

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

          Qt currently does not provide global shortcuts like that. IIRC, there was libQxt that did at the time.

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

          J 1 Reply Last reply
          2
          • SGaistS SGaist

            Qt currently does not provide global shortcuts like that. IIRC, there was libQxt that did at the time.

            J Offline
            J Offline
            joac
            wrote on last edited by
            #5

            @SGaist said in Shortcuts for SysTrayIcon:

            Qt currently does not provide global shortcuts like that. IIRC, there was libQxt that did at the time.

            Thanks for your response.

            It sounds like https://pypi.org/project/PyGlobalShortcut/ does what I need, so I will have a look.

            Do you know if there are any plans to expand functionality to support something like this directly in Qt?

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

              There's QTBUG-5183 tracking it. I would say: patches welcome :-)

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

              J 1 Reply Last reply
              1
              • SGaistS SGaist

                There's QTBUG-5183 tracking it. I would say: patches welcome :-)

                J Offline
                J Offline
                joac
                wrote on last edited by
                #7

                @SGaist said in Shortcuts for SysTrayIcon:

                There's QTBUG-5183 tracking it. I would say: patches welcome :-)

                Hi again

                Unfortunately, https://pypi.org/project/PyGlobalShortcut/ does not resolve the issue.

                A possible solution is pynput's (https://pynput.readthedocs.io/en/latest/) keyboard which allows something like:

                self.hotkey = keyboard.GlobalHotKeys({'<ctrl>+<alt>+h': self.shortcut_function})
                self.hotkey.start()
                

                The SysTrayIcon application properly catches this, but it gives the following exception:

                QObject: Cannot create children for a parent that is in a different thread.
                

                There are numerous ways in which I can support shortcuts in general, e.g. by using QShortCut and QKeySequence. The issue arises when the application is not in focus; indeed when it is a SysTrayIcon. I have not yet managed to resolve this.

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

                  The Qxt library was providing something for that. You could make a small library with that and the make python bindings for it.

                  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
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved