qt5 catch input from qtextedit

397 Views Asked by At

I am working on a small application which is basically a serial terminal with some added stuff.

for the terminal window I use the QTextEdit widget and allready overload add and overload some methods. However since this is a serial terminal I don't want the input that the user is typing in the QTextEdit to actually end up there. Most serial communication channels echo back the input that is send to them and I would like to show this in the QTextEdit and not what the user inputs.

The ideal would be I could overload the way QTextEdit handles its input and I work from there.

I have looked online but I can't seem to find what I am looking for. Maybe I am using the wrong search terms

1

There are 1 best solutions below

0
On BEST ANSWER

You can set the QTextEdit widget to read-only mode and then just listen for its key events. That way nothing will be displayed in the QTextEdit and you will be able to intercept the keys.

If you subclass QTextEdit and reimplement the keyPressevent, you might want to call the base class implementation inside it. Otherwise you might not get the functionalities that for example page-up/page-down keys provide.