[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: Defining INS (insert) shortcut in macOS
From: Jeremy Katz <jkatz () volexity ! com>
Date: 2021-05-25 20:30:12
Message-ID: 58b97aac-f697-2f83-1175-bce3b06b8128 () volexity ! com
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
[Attachment #4 (multipart/mixed)]
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@gmail.com
> <mailto:maurizio.berti@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@gmail.com <mailto:rodrigobraz@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@gmail.com <mailto:maurizio.berti@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@gmail.com <mailto:rodrigobraz@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>
>
["events.py" (text/x-python-script)]
import PyQt5.QtCore as QtCore
import PyQt5.QtWidgets as QtWidgets
class Widget(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.eventTypeToStr = { getattr(QtCore.QEvent, key): key for key in \
dir(QtCore.QEvent) if key[0].isupper() } self.installEventFilter(self)
def eventFilter(self, object, event):
print(QtCore.QDateTime.currentDateTime().toString(), object, \
self.eventTypeToStr[event.type()]) return super().eventFilter(object, event)
class NativeEventFilter(QtCore.QAbstractNativeEventFilter):
def nativeEventFilter(self, first, second):
print(QtCore.QDateTime.currentDateTime().toString(), "nativeEventFilter", \
first, second) return (False, 0)
app = QtWidgets.QApplication([])
nativeEventFilter = NativeEventFilter()
app.installNativeEventFilter(nativeEventFilter)
w = Widget()
w.show()
app.exec()
["OpenPGP_0x095F4F2148BF111D.asc" (application/pgp-keys)]
["OpenPGP_signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic