View Full Version : How to use QInputContextFactory ?

12th September 2009, 14:48
The documentation of the QtInputContext class includes the following paragraph:

"Multiple input contexts that is belonging to a single input method may concurrently coexist. Suppose multi-window text editor. Each text widget of window A and B holds different QInputContext instance which contains different state information such as partially composed text."

I need to do something like this. There are two textboxes in the UI which should remember their input state. For example, when using the Korean keyboard layout on Windows, the keyboard state indicator will have an additional button labelled 'A' which can be used to switch between input in the Latin alphabet or Hangul (the Korean one). I would like the two text boxes to "remember" whether Hangul or Latin input was used in them last time, so no manual switching is necessary. Just type in a box and the last alphabet should be used automatically.

I thought that this could be achieved by associating a new QInputContext with each textbox, using QWidget::setInputContext. I subclassed QTextEdit, and added the following in the constructor:

setInputContext(QInputContextFactory::create("win", this));

("win" is what QInputContextFactory::keys() returns on my WinXP machine, usually in two instances.)

This did not achieve the desired result. I also tried configuring Qt to use native widgets, but that did not help either.

How can each text box be given its own input context, so they remember their input state, as the documentation mentions?

Even after a lot of searching around, I wasn't able to find any useful information about this :( Any suggestions would be greatly appreciated.