I want to detect when backspace is pressed in a QPlainTextEdit widget.
I have the following code:
def keyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Backspace:
print("Backspace pressed")
(in a class inherited from QPlainTextEdit)
The problem is that now pressing backspace (or any other character key) does not insert the character into the text box. I could check for every key and do it that way, however, especially with large files, removing the last character could be inefficient, slow and result in messy code.
Is there a better way of doing this?