Defining INS (insert) shortcut in macOS

Rodrigo de Salvo Braz rodrigobraz at
Tue May 25 15:01:33 BST 2021

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):

        self.setWindowTitle("INS Test")

        quit_action = QAction("E&xit", self)
        quit_action.setStatusTip("Exit application")

        insert_action = QAction("&Insert", self)
        # insert_action.setShortcut(QKeySequence("Ins"))
        # insert_action.setShortcut(QKeySequence(Qt.ALT + Qt.Key_P))

        menu = self.menuBar()

        menu = menu.addMenu("&Action")

        self.counter = 0
        self.label = QLabel(f"Insert selected {self.counter} times.")


    def insert_task(self):
        self.counter += 1
        self.label.setText(f"Insert selected {self.counter} times.")

app = QApplication(sys.argv)
w = MainWindow()


On Mon, May 24, 2021 at 4:43 PM Maurizio Berti <maurizio.berti at>

> 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> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the PyQt mailing list