The QInputMethodEvent class provides parameters for input method events. 更多...
| 頭: | #include <QInputMethodEvent> |
| qmake: | QT += gui |
| 繼承: | QEvent |
| class | Attribute |
| enum | AttributeType { TextFormat, Cursor, Language, Ruby, Selection } |
| QInputMethodEvent () | |
| QInputMethodEvent (const QString & preeditText , const QList<Attribute> & 屬性 ) | |
| QInputMethodEvent (const QInputMethodEvent & other ) | |
| ~QInputMethodEvent () | |
| const QList<Attribute> & | attributes () const |
| const QString & | commitString () const |
| const QString & | preeditString () const |
| int | replacementLength () const |
| int | replacementStart () const |
| void | setCommitString (const QString & commitString , int replaceFrom = 0, int replaceLength = 0) |
The QInputMethodEvent class provides parameters for input method events.
輸入法事件被發送給 Widget,當使用輸入法把文本鍵入 Widget 時。輸入法被廣泛用於鍵入非拉丁字母語言的文本。
注意:當創建自定義文本編輯 Widget 時, Qt::WA_InputMethodEnabled 窗口屬性必須被明確設置 (使用 QWidget::setAttribute () 函數) 為接收輸入法事件。
希望能夠正確處理具有復雜字符輸入的語言的鍵盤鍵入 Widget 的作者,對這些事件很感興趣。這種語言的文本輸入過程通常分 3 個步驟:
當用戶在鍵盤上按下首個鍵時,輸入上下文被創建。此輸入上下文將包含已鍵入字符的字符串。
當每按下一個新鍵,輸入法會試著為迄今為止鍵入的文本創建匹配字符串 (又稱預編輯字符串)。當輸入上下文處於活動狀態時,用戶隻可以把光標移入屬於此輸入上下文的字符串中。
在某個時間點,用戶會激活用戶界麵組件 (或許使用特定鍵),在那裏用戶可以從大量匹配迄今為止鍵入文本的字符串中進行選擇。用戶可以確認他們的選擇 (或取消輸入);無論哪種情況,都會關閉輸入上下文。
QInputMethodEvent models these three stages, and transfers the information needed to correctly render the intermediate result. A QInputMethodEvent has two main parameters: preeditString () 和 commitString ()。 preeditString () 參數給齣目前活動的預編輯字符串。 commitString () 參數給齣應添加到編輯器 Widget 文本 (或部分替換) 的文本。它通常是輸入操作的結果,且必須直接插入 Widget 文本 (在預編輯字符串之前)。
若 commitString () 應替換部分編輯器文本, replacementLength () 將包含要替換的字符數。 replacementStart () 包含相對於預編輯字符串開頭的要替換字符的位置。
許多屬性控製著預編輯字符串的視覺外觀 (預編輯字符串外的文本視覺外觀僅由 Widget 控製)。 AttributeType 枚舉描述瞭可以設置的不同屬性。
類實現 QWidget::inputMethodEvent () 或 QGraphicsItem::inputMethodEvent () 至少應該理解和尊重 TextFormat and Cursor 屬性。
由於輸入法需要能夠從 Widget (或圖形項) 查詢某些特性,因此子類也必須實現 QWidget::inputMethodQuery () 和 QGraphicsItem::inputMethodQuery () 分彆。
當收到輸入法事件時,文本 Widget 必須履行以下步驟:
置換時預編輯字符串區域被忽略,因此從 -1 開始長度為 2 的置換將移除預編輯字符串之前的最後 1 個字符和之後的第 1 個字符,並將提交字符串直接插入預編輯字符串之前。
若 Widget 有實現撤銷/重做,此操作將被添加到撤銷堆棧。
若 Widget 有實現撤銷/重做, preeditString () 不應該以任何方式影響撤消/重做堆棧。
Widget 應審查要應用於預編輯字符串的屬性列錶。它必須至少理解 TextFormat 和 Cursor 屬性及按指定渲染它們。
另請參閱 QInputMethod .
| 常量 | 值 | 描述 |
|---|---|---|
QInputMethodEvent::TextFormat
|
0
|
A QTextCharFormat 用於由 start 和 length 指定的預編輯字符串部分。值包含 QVariant 類型 QTextFormat specifying rendering of this part of the preedit string. There should be at most one format for every part of the preedit string. If several are specified for any character in the string the behaviour is undefined. A conforming implementation has to at least honor the backgroundColor, textColor and fontUnderline properties of the format. |
QInputMethodEvent::Cursor
|
1
|
If set, a cursor should be shown inside the preedit string at position start. The length variable determines whether the cursor is visible or not. If the length is 0 the cursor is invisible. If value is a QVariant 類型 QColor this color will be used for rendering the cursor, otherwise the color of the surrounding text will be used. There should be at most one Cursor attribute per event. If several are specified the behaviour is undefined. |
QInputMethodEvent::Language
|
2
|
The variant contains a QLocale object specifying the language of a certain part of the preedit string. There should be at most one language set for every part of the preedit string. If several are specified for any character in the string the behavior is undefined. |
QInputMethodEvent::Ruby
|
3
|
The ruby text for a part of the preedit string. There should be at most one ruby text set for every part of the preedit string. If several are specified for any character in the string the behaviour is undefined. |
QInputMethodEvent::Selection
|
4
|
If set, the edit cursor should be moved to the specified position in the editor text contents. In contrast with
Cursor
, this attribute does not work on the preedit text, but on the surrounding text. The cursor will be moved after the commit string has been committed, and the preedit string will be located at the new edit position. The start position specifies the new position and the length variable can be used to set a selection starting from that point. The value is unused.
|
另請參閱 Attribute .
構造事件為類型 QEvent::InputMethod 。 attributes (), preeditString (), commitString (), replacementStart (),和 replacementLength () 被初始化為默認值。
另請參閱 setCommitString ().
構造事件為類型 QEvent::InputMethod 。預編輯文本被設為 preeditText ,屬性為 屬性 .
The commitString (), replacementStart (),和 replacementLength () 值可以設置使用 setCommitString ().
另請參閱 preeditString () 和 attributes ().
構造副本為 other .
Destroys the instance of QInputMethodEvent.
返迴的屬性列錶會被傳遞給 QInputMethodEvent 構造函數。屬性控製預編輯字符串的視覺外觀 (預編輯字符串外的文本視覺外觀僅由 Widget 控製)。
另請參閱 preeditString () 和 Attribute .
返迴應添加到編輯器 Widget 文本 (或替換部分) 的文本。通常是輸入操作的結果,且必須直接插入 Widget 文本 (在預編輯字符串之前)。
另請參閱 setCommitString (), preeditString (), replacementStart (),和 replacementLength ().
返迴預編輯文本,即:用戶開始編輯之前的文本。
另請參閱 commitString () 和 attributes ().
返迴預編輯字符串中要被替換的字符數。
另請參閱 replacementStart () 和 setCommitString ().
返迴要替換字符的位置,相對於預編輯字符串開頭。
另請參閱 replacementLength () 和 setCommitString ().
把提交字符串設為 commitString .
提交字符串是應添加到編輯器 Widget 文本 (或替換部分) 的文本。通常是輸入操作的結果,且必須直接入到 Widget 文本 (在預編輯字符串之前)。
If the commit string should replace parts of the of the text in the editor, replaceLength 指定要替換的字符數。 replaceFrom 指定要替換字符相對預編輯字符串開頭的位置。
另請參閱 commitString (), replacementStart (),和 replacementLength ().