QT 嵌入式 輸入法 軟鍵盤

2021-07-01 23:38:06 字數 1347 閱讀 6065

設計自己的輸入法需要繼承qwsinputmethod。

需要重新實現:

virtual void

updatehandler ( int type );    

//type值是列舉變數update, focusin, focusout, reset, destroyed

分別對應:擁有焦點的控制項發生變化(例如qlineedit的位置發生變化),需要輸入法做出相應的改變(軟鍵盤位置)

新控制項開始擁有焦點。(需要彈出輸入法)

原有控制項失去焦點(需要關閉輸入法)

重啟輸入法(可以在系統語言發生變化時,重新配置輸入法)

輸入法銷毀(基本用不到)

void myinputmethod::updatehandler(int type)

}break;

case focusout:

if(mactive)

break;

case reset:

//reset inputmethod

break;

case destroyed:

break;

}}

不同使用者的keyboard實現方法不一樣,同時在keyboard中繼承相應的輸入法。英文軟鍵盤可參考:

另外,再實現2個槽函式,用於接受軟體盤或者輸入法輸出的字元(假如當使用者按鍵a後,字母a需要被myinputmethod知道)

void myinputmethod::commitcharacter(qstring str)

void myinputmethod::preeditcharacter(qstring str)

為了讓得到的字元或者字串顯示到編輯框中可以使用 sendcommitstring和sendpreeditstring

commitstring和preeditstring的區別是什麼?

在t9輸入法中,輸入數字2得到字母a,再輸入數字2得到字母b。a和b顯示時帶有下劃線且閃爍。這是呼叫sendpreeditstring實現的。preeditstring,顧名思義預編輯的。

當連續2次輸入數字2後,等待一段時間後,preeditstring 'b'需要變為commitstring 'b'。這是呼叫sendcommitstring實現的。

上面3個函式實現後,整個輸入法的框架也就搞定了。剩下的就是:如何顯示鍵盤,如何繫結輸入法並輸出正確的preeditstring和commitstring了。

當然,為了讓qt執行時能夠識別,需要進行註冊:

qwsserver::setcurrentinputmethod(new myinputmethod());

開啟和關閉輸入法軟鍵盤

netcf還是沒有支援的函式,那麼,就呼叫api吧,函式名為sipshowim。msdn中這樣描述 requirements os versions windows ce 2.10 and later.header sipapi.h.link library coredll.lib.bool sip...

開啟和關閉輸入法軟鍵盤

netcf還是沒有支援的函式,那麼,就呼叫api吧,函式名為sipshowim。msdn中這樣描述 requirements os versions windows ce 2.10 and later.header sipapi.h.link library coredll.lib.bool sip...

Window mobile 軟鍵盤輸入法設定

input method manager,簡稱imm using microsoft.windowsce.forms inputpanel ip new inputpanel foreach inputmethod p in ip.inputmethods immreleasecontext hwn...