How to recognize chinese keyboard [solved]
-
QInoutMethod class might be of some help.
What do you plan to do with the information? -
Hi.
Thank you for the answer.I could not really find such information from QInputMethod...
Anyway I have a bug in a QTableView + QStyledItemDelegate for the chinese users.
When the tableview is triggered with QAbstractItemView::EditTrigger::AnyKeyPressed, the key is not sent to pinyin, but directly written in the QLineEdit.As a result they have something like this:
f 啊让人the f is the char that fired up my QLineEdit.
-
Well even if there was/is a proper way to query the input method that is in use,
you would need a really long list of all possible input methods that builds the
characters from compounds. I think the easiest way would simply to use DoubleClick
instead if AnyKeyPressed. For me personally it would seem illogical to try to input
new text to what appears to be a read only field. Even better would simply be to
activate the edit mode when ever a cell is selected CurrentChanged. -
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); }