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. PyQt6 Control keyboard shortcut not working
Forum Updated to NodeBB v4.3 + New Features

PyQt6 Control keyboard shortcut not working

Scheduled Pinned Locked Moved Solved Qt for Python
8 Posts 2 Posters 1.8k 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.
  • MalonnM Offline
    MalonnM Offline
    Malonn
    wrote on last edited by
    #1

    I cannot get my application to recognize the control key. I have two QTreeViews in a group, and some QPushButtons in a group. I am using PushButton.setShortcut() to attach a shortcut. Other keys seem to work fine. It's just the modifiers (ctrl, shift, alt) that don't. This is what I've tried:
    QPushButton.setShortcut('ctrl')
    QPushButton.setShortcut(QKeySequence('ctrl'))
    QPushButton.setShortcut(QKeySequence(0x01000021)) # ctrl key
    QPushButton.setShortcut(QKeySequence(0x04000000)) # modifier

    I've also tried with members. In reality, I want a key combination. But, to get there I need to get my app to recognize ctrl first. QTreeViews' shortcuts work fine, including those that use ctrl. So, I know it's not an OS (Fedora KDE Plasma) issue.

    Any ideas? Are my trees disabling ctrl? I don't understand why a widget would do that, nor do I think it would.

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

      Hi,

      Ctrl is not a key, it's a modifier. You cannot make a key sequence out of it alone. It must be combined with another key (shift is also a modifier and not a key).

      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
      • MalonnM Offline
        MalonnM Offline
        Malonn
        wrote on last edited by
        #3

        Cool, thanks. However, I have tried to combine Ctrl with F1 (the combo I actually want to use) via setShortcut('Ctrl+F1'), and it does not work. Also, I have attempted to grab hold of something by print(shortcut().toString()) to see, and all modifiers print human readable text except Ctrl (an empty string). Now, printing shortcut() always prints a QKeySequence object, but no modifiers work. It could be the way I combine modifiers (+ or |), but I can't find any reference on how to do it any other way.

        Something funny is going on. It must be my understanding, but I've hit a wall.

        SGaistS 1 Reply Last reply
        0
        • MalonnM Malonn

          Cool, thanks. However, I have tried to combine Ctrl with F1 (the combo I actually want to use) via setShortcut('Ctrl+F1'), and it does not work. Also, I have attempted to grab hold of something by print(shortcut().toString()) to see, and all modifiers print human readable text except Ctrl (an empty string). Now, printing shortcut() always prints a QKeySequence object, but no modifiers work. It could be the way I combine modifiers (+ or |), but I can't find any reference on how to do it any other way.

          Something funny is going on. It must be my understanding, but I've hit a wall.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Which platform are you on ?
          Can you provide a minimal script that shows this 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
          • MalonnM Offline
            MalonnM Offline
            Malonn
            wrote on last edited by
            #5

            I am on Fedora 38 KDE Plasma. Further testing reveals that 'Shift+F1' works, and 'Alt+<anything>' does not work as it is used by my OS (opens "start menu").

            I really appreciate that you want to help, but I just don't feel like extracting the relevant bits from my multi-module project. So, I accept that you may drop me like a hot potato now, but I can always use 'Shift+F1'. Not what I want, and I have no clue why Qt is behaving this way for future reference, but it will get the job done.

            If my OS points you to an idea, I'm all ears. But, I'm not on a Mac.

            SGaistS 1 Reply Last reply
            0
            • MalonnM Offline
              MalonnM Offline
              Malonn
              wrote on last edited by
              #6

              I just thought of something. I am using a subclassed QMainWindow, and I read while troubleshooting (which I've done a lot of) that Ctrl is tied to the menubar of a QMainWindow. I don't know if that's relevant, but it's worth testing as long as I can accept the extra code required to implement a QAction that has a signal emitted by my clicked signal.

              Thoughts on QMainWindow's blocking modifiers? I don't lean that way, but shortcuts are new to me.

              1 Reply Last reply
              0
              • MalonnM Malonn

                I am on Fedora 38 KDE Plasma. Further testing reveals that 'Shift+F1' works, and 'Alt+<anything>' does not work as it is used by my OS (opens "start menu").

                I really appreciate that you want to help, but I just don't feel like extracting the relevant bits from my multi-module project. So, I accept that you may drop me like a hot potato now, but I can always use 'Shift+F1'. Not what I want, and I have no clue why Qt is behaving this way for future reference, but it will get the job done.

                If my OS points you to an idea, I'm all ears. But, I'm not on a Mac.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Did you check the keyboard shortcuts configuration ?
                You might be using inadvertently something that is already taken.

                KDE has quite an extensive list of shortcuts to allow for almost mouse less usage.

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

                MalonnM 1 Reply Last reply
                1
                • SGaistS SGaist

                  Did you check the keyboard shortcuts configuration ?
                  You might be using inadvertently something that is already taken.

                  KDE has quite an extensive list of shortcuts to allow for almost mouse less usage.

                  MalonnM Offline
                  MalonnM Offline
                  Malonn
                  wrote on last edited by Malonn
                  #8

                  @SGaist I did. The combo is not spoken for. I'll double check though. I've troubleshot a lot, and can't recall all I've tried to detail in a post here. It still wouldn't explain why I can't get the Ctrl key to print, while other modifiers do.

                  There might not be much people here can do unless I man up and post an MRE.

                  EDIT: Oops! You are right @SGaist . The OS shortcut slipped under the cracks. Alt+F1 is assigned to KWin, and it blocks my app from using it. Damn, wish I would have not missed that earlier—would have saved hours of troubleshooting.

                  1 Reply Last reply
                  0
                  • MalonnM Malonn has marked this topic as solved on

                  • Login

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