Qt currently does not have the capabilities to detect if a key is pressed... the same does not have the capabilities I need.
So I had to use native code:
#ifdef Q_OS_WIN
#include "Windows.h"
#endif
...
bool MyTableView::edit(const QModelIndex & index, EditTrigger trigger, QEvent * ev)
{
if (trigger == AnyKeyPressed)
{
#ifdef Q_OS_WIN
HKL lang_id = GetKeyboardLayout(0); // get the current keyboard layout
unsigned short prim_lang = LOBYTE(lang_id); //take only the primary language identifier
switch (bytes.toInt())
{
case 0x04: //Chinese
case 0x11: //Japanese
/* maybe other future languages that use special input methods */
//clear current content, then the editor will be open with pinyin activated
QKeyEvent* toSend = new QKeyEvent(QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier);
return QAbstractItemView::edit(index, trigger, toSend);
}
#endif
}
return QAbstractItemView::edit (index, trigger, ev);
}