Use keyPressEvent to catch enter or return

Viewed 13732

I have a simple form with some combos, labels, buttons and a QTextEdit.

I try to catch the enter or return key with keyPressEvent, but for some reason I'm not able to. The ESC key however, that I also use, is recognized.

Here's a piece of the code:

 def keyPressEvent(self, e):
    print e.key()
    if e.key() == QtCore.Qt.Key_Return:
        self.created.setText('return')
    if e.key() == QtCore.Qt.Key_Enter:
        self.created.setText('enter')
    if e.key() == QtCore.Qt.Key_Escape:
        self.cmbEdit = not(self.cmbEdit)
        if self.cmbEdit:

etc...

Am I missing something?

1 Answers
Related