Swoogan
Swoogan

Reputation: 5558

QTextEdit receives Control Key doesn't pass to main window

I have a QTextEdit on my QMainWindow. I have overridden my main window keyPressEvent method and put a few hotkey handlers in there (ie: Ctrl+J, Ctrl+K). These hotkeys are global to the application.

The issue I have is that when the QTextEdit widget has focus, these key presses seem to be consumed by the widget and never seen by the form. The interesting thing is that these key combos do nothing in the QTextEdit.

How can I have the QTextEdit ignore key combinations that it has no behaviour associated with? Alternatively, how might I accomplish my goal in Qt?

Upvotes: 0

Views: 134

Answers (1)

Whichever widget has the keyboard focus will nominally consume all keyboard events. There's no notion of an "unhandled" keyboard event. Qt's event semantics for keyboard events don't work that way.

You need to use a QShortcut. Internally, it acts as an application-wide event filter for keystroke sequences, it's tied into the private implementation of QApplication. The only other way for you to do it would be to act as an application-wide event filter that acts on keystroke events.

Upvotes: 1

Related Questions