Defining INS (insert) shortcut in macOS

Rodrigo de Salvo Braz rodrigobraz at gmail.com
Tue May 25 15:12:48 BST 2021


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>
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> 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>
>> 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> 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
>>>
>>
>
> --
> È difficile avere una convinzione precisa quando si parla delle ragioni
> del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210525/27aee45c/attachment.htm>


More information about the PyQt mailing list