That is because you have overridden the keyPressEvent of your MainWindow and not of the QTextEdit.but the problem is when any key press inside the textedit will not produce any outcome,
You have two options:
1. Use an event filter - this way you don't need to subclass QTextEdit.
Look in the docs for the QObejct::installEventFilter() they have a "key eater" example there.
2. Subclass QTextEdit and re implement its keyPressEvent().
Bookmarks