InputMethod QML Type

用于在 QML 中创建输入法的基本类型。更多

Import Statement: import QtQuick.VirtualKeyboard

属性

信号

方法

详细说明

InputMethod 类型可让您创建自定义输入法,并将其分配给InputEngine

属性文档

inputContext : InputContext [read-only]

输入上下文。


inputEngine : InputEngine [read-only]

输入引擎


信号文档

selectionListActiveItemChanged(int type, int index)

type 标识的选择列表中的当前index 发生变化时,输入法会发出该信号。

注: 相应的处理程序是onSelectionListActiveItemChanged


selectionListChanged(int type)

当选择列表的内容发生变化时,输入法会发出此信号。type 参数指定哪个选择列表发生了变化。

注: 相应的处理程序是onSelectionListChanged


[since QtQuick.VirtualKeyboard 2.2] selectionListsChanged()

当选择列表类型发生变化时,输入法会发出该信号。该信号将触发对selectionLists() 方法的调用,允许输入法更新选择列表类型。

注: 相应的处理程序是onSelectionListsChanged

此信号在 QtQuick.VirtualKeyboard 2.2 中引入。


方法文档

[since QtQuick.VirtualKeyboard 2.4] bool clickPreeditText(int cursorPosition)

当用户点击cursorPosition 上的预编辑文本时调用。

如果函数处理了事件,则应返回true 。否则,输入将返回reselect() 进行进一步处理。

此方法在 QtQuick.VirtualKeyboard 2.4 中引入。


list<int> inputModes(string locale)

返回locale 的输入模式列表。


bool keyEvent(int key, string text, int modifiers)

本方法的目的是处理输入引擎生成的按键事件。

key 参数指定了要处理的按键代码。按键代码不区分大写字母和非大写字母。text 参数包含按键的 Unicode 文本。modifiers 参数包含适用于key 的密钥修改器。

如果成功处理了键事件,则此方法返回true 。如果返回值为false ,则键事件将重定向到默认输入法进行进一步处理。


[since QtQuick.VirtualKeyboard 2.0] list<int> patternRecognitionModes()

返回支持的模式识别模式列表。

输入引擎调用本方法来查询支持的模式识别模式列表。

该方法在 QtQuick.VirtualKeyboard 2.0 中引入。


[since QtQuick.VirtualKeyboard 2.0] bool reselect(int cursorPosition, int reselectFlags)

此方法尝试重新选择位于cursorPosition 的单词。reselectFlags 定义了与光标位置相关的单词选择规则。

  • InputEngine.WordBeforeCursor 激活光标前的单词。如果只使用该标志,则单词必须正好在光标处结束。
  • InputEngine.WordAfterCursor 激活光标后的单词。专门使用该标记时,单词必须从光标处开始。
  • InputEngine.WordAtCursor 在光标处激活单词。该标志是上述标志的组合,但单词不能在光标处开始或停止。

如果成功重新选择了单词,该方法返回true

该方法在 QtQuick.VirtualKeyboard 2.0 中引入。


reset()

当该输入法需要重置时,输入引擎会调用该方法。输入法必须仅重置其内部状态。与update() 方法的主要区别在于,reset() 只修改输入法状态,而不能修改输入上下文。


var selectionListData(int type, int index, int role)

返回由type 标识的选择列表的项目数据。role 参数指定所请求的数据。index 参数是基于零的选择列表索引。


int selectionListItemCount(int type)

返回由type 标识的选择列表中的项目数。


void selectionListItemSelected(int type, int index)

当用户选择了index 中的项目时,将调用此方法。选择列表由type 参数标识。


list<int> selectionLists()

返回此输入法使用的选择类型列表。

当输入法被激活以及每次更新输入法提示时,输入引擎都会调用此方法。输入法可以通过返回所需的选择列表类型来保留选择列表。

输入法可随时通过发出selectionListsChanged() 信号请求输入引擎更新选择列表。该信号将触发对该方法的调用,从而允许输入法更新选择列表类型。


bool setInputMode(string locale, int inputMode)

为该输入法更改inputModelocale 。如果成功,该方法将返回true


bool setTextCase(int textCase)

更新此输入法的textCase 。如果成功,该方法将返回true

文本大小写的可能值是

  • InputEngine.Lower 小写文本。
  • InputEngine.Upper 大写文本。

[since QtQuick.VirtualKeyboard 2.0] Trace traceBegin(int traceId, int patternRecognitionMode, var traceCaptureDeviceInfo, var traceScreenInfo)

当与指定的patternRecognitionMode 开始跟踪交互时,将调用此方法。跟踪由traceId 唯一标识。traceCaptureDeviceInfo 提供有关源设备的信息,traceScreenInfo 提供有关屏幕上下文的信息。

如果输入法接受事件并希望捕获跟踪输入,则必须返回一个新的跟踪对象。在调用InputMethod.traceEnd() 方法之前,该对象必须保持有效。如果跟踪被呈现在屏幕上,它将一直存在,直到跟踪对象被销毁。

此方法在 QtQuick.VirtualKeyboard 2.0 中引入。


[since QtQuick.VirtualKeyboard 2.0] bool traceEnd(Trace trace)

跟踪交互结束时会调用此方法。输入法应在调用此函数后的某个时刻销毁trace 对象。成功时返回true

如何访问收集的数据,请参阅 "输入方法的跟踪 API"。

此方法在 QtQuick.VirtualKeyboard 2.0 中引入。


update()

当输入法需要更新时,输入引擎会调用此方法。输入法必须关闭当前的编辑前文本,并将内部状态恢复为默认状态。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.