PDA

View Full Version : How do I trigger QTextEdit.inputMethodEvent() for keyboard events?



houzi
14th July 2014, 15:37
I have created the backend code for my keyboard driver. The driver will take roman characters as input and output Tibetan Unicode.
I would like to embed this driver in my application and I am currently trying to understand the best way to achieve this.

I know I could hack together something where I handle events for every single character that might be inputted, but this seems like a really ugly hack where I'm trying to poorly reinvent functionality that seems to already be available in Qt, namely through QInputMethodEvent, since it seems to handle intermediate states where a partially typed string will not yield valid output from my driver.

I have subclassed QTextEdit, called the object's .setAttribute(Qt.WA_InputMethodEnabled) and tried to implement inputMethodEvent() and see if this event is triggered by keypresses, but inputMethodEvent() isn't called at all.

I found that there's also QInputContext, which can send a QInputMethodEvent, but since I'm not very familiar with Qt yet and trying to learn by doing this, I'm not sure how I utilize QInputContext.

Basically I would like to be able to do the following:



Intercept keyboard events and pass them to a buffer
Process the buffer with my driver.

a. Represent intermediate states in the QTextEdit widget.
b. Replace the intermediate output in the QTextEdit widget with the completed Tibetan Unicode word


I am completely lost, so any help whatsoever would be of tremendous benefit. Just knowing how to trigger the inputMethodEvent() would be a great start.

Thank you.