I have an element, editorBox
which is of the PyQt5 element type QPlainTextEdit
. My target goal is to call a function when the hotkey Shift + Return
is pressed, and my goal with this function is that it will also insert text into the editorBox element (this isn't the part I'm stressed about, it's fairly easy to do with the .insertPlainText()
method).
I've done searching, and the closest result I could find was to use QShortcut
& QKeySequence
paired together like so:
# Initialize the QShortcut class
self.keybindShiftEnter = QShortcut(QKeySequence("Shift+Return"), self)
# Connect the shortcut event to a lambda which executes my function
self.keybindShiftEnter.activated.connect(lambda: self.editorBox.insertPlainText("my text to insert"))
For clarification, I have tried using other characters in the QKeySequence
constructor, such as Ctrl+b
, and I've had success with it. Oddly enough, only the combination Shift+Return
doesn't work for me.
I've analyzed a problem with it in relation to my bug. Some of the posts I've viewed: