Defining INS (insert) shortcut in macOS

Jeremy Katz jkatz at volexity.com
Tue May 25 21:30:12 BST 2021


Using PyQt and Qt 5.15.2 on macOS Big Sur:

A native event for key press and release appears to be received for
insert, as with any other key.

QEvent key releases are generated. Key presses are not.


On 25/May/21 07:12, Rodrigo de Salvo Braz wrote:
> Thanks for testing it on Linux, Maurizio.
> 
> Yes, hopefully someone on the Mac can give me an idea.
> 
> I'm using Qt 5.15.4 and am on macOS Catalina 10.15.7.
> 
> Rodrigo
> 
> On Tue, May 25, 2021 at 7:09 AM Maurizio Berti <maurizio.berti at gmail.com
> <mailto:maurizio.berti at gmail.com>> wrote:
> 
>     It works fine on Linux, so it might be an issue related to MacOS (or
>     a specific version of it).
>     Let's see if anyone using that OS can reproduce it. In the meantime,
>     it might be useful to know which version of Qt and MacOS you are
>     using, so that others can confirm it for other configurations too.
> 
>     Maurizio
> 
>     Il giorno mar 25 mag 2021 alle ore 16:01 Rodrigo de Salvo Braz
>     <rodrigobraz at gmail.com <mailto:rodrigobraz at gmail.com>> ha scritto:
> 
>         Hi Maurizio,
> 
>         Here's a minimal reproducible example.
> 
>         The action works on the menu, and a modifier-based shortcut
>         (here, Alt-P, after uncommenting out) works as well.
> 
>         But when I use "Ins" or Qt.Key_Insert, it does not work.
> 
>         import sys
> 
>         from PyQt5.QtCore import Qt
>         from PyQt5.QtGui import QKeySequence
>         from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QLabel
> 
> 
>         class MainWindow(QMainWindow):
> 
>             def __init__(self):
>                 super().__init__()
> 
>                 self.setWindowTitle("INS Test")
> 
>                 quit_action = QAction("E&xit", self)
>                 quit_action.setStatusTip("Exit application")
>                 quit_action.triggered.connect(self.close)
>                 quit_action.setShortcut(QKeySequence.Quit)
> 
>                 insert_action = QAction("&Insert", self)
>                 insert_action.setStatusTip("Insert")
>                 insert_action.triggered.connect(self.insert_task)
>                 insert_action.setShortcut(QKeySequence(Qt.Key_Insert))
>                 # insert_action.setShortcut(QKeySequence("Ins"))
>         # insert_action.setShortcut(QKeySequence(Qt.ALT + Qt.Key_P))
> 
>         menu = self.menuBar()
>                 menu.setNativeMenuBar(False)
> 
>                 menu = menu.addMenu("&Action")
>                 menu.addAction(insert_action)
>                 menu.addAction(quit_action)
> 
>                 self.counter = 0
>         self.label = QLabel(f"Insert selected {self.counter}times.")
>                 self.label.setAlignment(Qt.AlignCenter)
> 
>                 self.setCentralWidget(self.label)
> 
>             def insert_task(self):
>                 self.counter += 1
>         self.label.setText(f"Insert selected {self.counter}times.")
> 
> 
>         app = QApplication(sys.argv)
>         w = MainWindow()
>         w.show()
> 
>         app.exec_()
> 
> 
>         On Mon, May 24, 2021 at 4:43 PM Maurizio Berti
>         <maurizio.berti at gmail.com <mailto:maurizio.berti at gmail.com>> wrote:
> 
>             That shortcut is very generic and can be potentially "eaten"
>             by widgets that accept text input.
>             Does any other modifier-based shortcut work (excluding
>             standard text shortcuts, like ctrl-x or ctrl-a)?
>             Can you provide a minimal reproducible example?
> 
>             Il giorno lun 24 mag 2021 alle ore 19:46 Rodrigo de Salvo
>             Braz <rodrigobraz at gmail.com <mailto:rodrigobraz at gmail.com>>
>             ha scritto:
> 
>                 Hi,
> 
>                 I am trying to define an Insert shortcut in the macOS:
> 
>                 insert_action.setShortcut(QKeySequence(Qt.Key_Insert))
> 
>                 Also tried:
> 
>                 insert_action.setShortcut(QKeySequence("Ins"))
> 
>                 but neither option works (nothing happens). It does work
>                 when I run it on Windows.
> 
>                 I am using an external PC keyboard. I know the keyboard
>                 is generating the right key code because when I use the
>                 EventViewer of Karabiner-Elements (a keyboard-remapping
>                 application), I do see "key_code: insert" when I press
>                 the key.
> 
>                 Thanks,
> 
>                 Rodrigo
> 
> 
> 
>             -- 
>             È difficile avere una convinzione precisa quando si parla
>             delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
>             http://www.jidesk.net <http://www.jidesk.net>
> 
> 
> 
>     -- 
>     È difficile avere una convinzione precisa quando si parla delle
>     ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
>     http://www.jidesk.net <http://www.jidesk.net>
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: events.py
Type: text/x-python-script
Size: 893 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210525/78db1cfe/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x095F4F2148BF111D.asc
Type: application/pgp-keys
Size: 1757 bytes
Desc: OpenPGP public key
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210525/78db1cfe/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210525/78db1cfe/attachment-0001.sig>


More information about the PyQt mailing list