<div dir="ltr"><div>Hi Maurizio,</div><div><br></div><div>Here's a minimal reproducible example.</div><div><br></div><div>The action works on the menu, and a modifier-based shortcut (here, Alt-P, after uncommenting out) works as well.</div><div><br></div><div>But when I use "Ins" or Qt.Key_Insert, it does not work.</div><div><br></div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(0,0,128);font-weight:bold">import </span>sys<br><br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtCore <span style="color:rgb(0,0,128);font-weight:bold">import </span>Qt<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtGui <span style="color:rgb(0,0,128);font-weight:bold">import </span>QKeySequence<br><span style="color:rgb(0,0,128);font-weight:bold">from </span>PyQt5.QtWidgets <span style="color:rgb(0,0,128);font-weight:bold">import </span>QApplication, QMainWindow, QAction, QLabel<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">class </span>MainWindow(QMainWindow):<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span><span style="color:rgb(178,0,178)">__init__</span>(<span style="color:rgb(148,85,141)">self</span>):<br>        <span style="color:rgb(0,0,128)">super</span>().<span style="color:rgb(178,0,178)">__init__</span>()<br><br>        <span style="color:rgb(148,85,141)">self</span>.setWindowTitle(<span style="color:rgb(0,128,128);font-weight:bold">"INS Test"</span>)<br><br>        quit_action = QAction(<span style="color:rgb(0,128,128);font-weight:bold">"E&xit"</span>, <span style="color:rgb(148,85,141)">self</span>)<br>        quit_action.setStatusTip(<span style="color:rgb(0,128,128);font-weight:bold">"Exit application"</span>)<br>        quit_action.triggered.connect(<span style="color:rgb(148,85,141)">self</span>.close)<br>        quit_action.setShortcut(QKeySequence.Quit)<br><br>        insert_action = QAction(<span style="color:rgb(0,128,128);font-weight:bold">"&Insert"</span>, <span style="color:rgb(148,85,141)">self</span>)<br>        insert_action.setStatusTip(<span style="color:rgb(0,128,128);font-weight:bold">"Insert"</span>)<br>        insert_action.triggered.connect(<span style="color:rgb(148,85,141)">self</span>.insert_task)<br>        insert_action.setShortcut(QKeySequence(Qt.Key_Insert))<br>        <span style="color:rgb(128,128,128);font-style:italic"># insert_action.setShortcut(QKeySequence("Ins"))<br></span><span style="color:rgb(128,128,128);font-style:italic">        # insert_action.setShortcut(QKeySequence(Qt.ALT + Qt.Key_P))<br></span><span style="color:rgb(128,128,128);font-style:italic"><br></span><span style="color:rgb(128,128,128);font-style:italic">        </span>menu = <span style="color:rgb(148,85,141)">self</span>.menuBar()<br>        menu.setNativeMenuBar(<span style="color:rgb(0,0,128);font-weight:bold">False</span>)<br><br>        menu = menu.addMenu(<span style="color:rgb(0,128,128);font-weight:bold">"&Action"</span>)<br>        menu.addAction(insert_action)<br>        menu.addAction(quit_action)<br><br>        <span style="color:rgb(148,85,141)">self</span>.counter = <span style="color:rgb(0,0,255)">0<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(148,85,141)">self</span>.label = QLabel(<span style="color:rgb(0,128,128);font-weight:bold">f"Insert selected </span><span style="color:rgb(0,0,128);font-weight:bold">{</span><span style="color:rgb(148,85,141)">self</span>.counter<span style="color:rgb(0,0,128);font-weight:bold">}</span><span style="color:rgb(0,128,128);font-weight:bold"> times."</span>)<br>        <span style="color:rgb(148,85,141)">self</span>.label.setAlignment(Qt.AlignCenter)<br><br>        <span style="color:rgb(148,85,141)">self</span>.setCentralWidget(<span style="color:rgb(148,85,141)">self</span>.label)<br><br>    <span style="color:rgb(0,0,128);font-weight:bold">def </span>insert_task(<span style="color:rgb(148,85,141)">self</span>):<br>        <span style="color:rgb(148,85,141)">self</span>.counter += <span style="color:rgb(0,0,255)">1<br></span><span style="color:rgb(0,0,255)">        </span><span style="color:rgb(148,85,141)">self</span>.label.setText(<span style="color:rgb(0,128,128);font-weight:bold">f"Insert selected </span><span style="color:rgb(0,0,128);font-weight:bold">{</span><span style="color:rgb(148,85,141)">self</span>.counter<span style="color:rgb(0,0,128);font-weight:bold">}</span><span style="color:rgb(0,128,128);font-weight:bold"> times."</span>)<br><br><br>app = QApplication(sys.argv)<br>w = MainWindow()<br>w.show()<br><br>app.exec_()</pre></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 24, 2021 at 4:43 PM Maurizio Berti <<a href="mailto:maurizio.berti@gmail.com">maurizio.berti@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">That shortcut is very generic and can be potentially "eaten" by widgets that accept text input.<div>Does any other modifier-based shortcut work (excluding standard text shortcuts, like ctrl-x or ctrl-a)?<br>Can you provide a minimal reproducible example?</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno lun 24 mag 2021 alle ore 19:46 Rodrigo de Salvo Braz <<a href="mailto:rodrigobraz@gmail.com" target="_blank">rodrigobraz@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I am trying to define an Insert shortcut in the macOS:</div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"JetBrains Mono",monospace;font-size:9.8pt">insert_action.setShortcut(QKeySequence(Qt.Key_Insert))</pre></div><div>Also tried:</div><div><pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"JetBrains Mono",monospace;font-size:9.8pt">insert_action.setShortcut(QKeySequence(<span style="color:rgb(0,128,128);font-weight:bold">"Ins"</span>))<br></pre></div><div>but neither option works (nothing happens). It does work when I run it on Windows.<br></div><div><br></div><div>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.</div><div><br></div><div>Thanks,</div><div><br></div><div>Rodrigo<br></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</blockquote></div>