Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to recognize chinese keyboard [solved]
Forum Updated to NodeBB v4.3 + New Features

How to recognize chinese keyboard [solved]

Scheduled Pinned Locked Moved General and Desktop
pinyin
5 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JozzoloJ Offline
    JozzoloJ Offline
    Jozzolo
    wrote on last edited by Jozzolo
    #1

    Hello!

    Is there a way in Qt to determine if the user is writing with a different InputMethod? For Exemple Qt can tell me if they are using pinyin?

    Thanks!!!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Huulivoide
      wrote on last edited by
      #2

      QInoutMethod class might be of some help.
      What do you plan to do with the information?

      1 Reply Last reply
      0
      • JozzoloJ Offline
        JozzoloJ Offline
        Jozzolo
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Huulivoide
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • JozzoloJ Offline
            JozzoloJ Offline
            Jozzolo
            wrote on last edited by
            #5

            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);
            }
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved