QInputMethod 类

QInputMethod 类提供对活动文本输入法的访问。 更多...

头: #include <QInputMethod>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QObject

公共类型

enum Action { Click, ContextMenu }

特性

公共函数

QRectF anchorRectangle () const
QRectF cursorRectangle () const
Qt::LayoutDirection inputDirection () const
QRectF inputItemClipRectangle () const
QRectF inputItemRectangle () const
QTransform inputItemTransform () const
bool isAnimating () const
bool isVisible () const
QRectF keyboardRectangle () const
QLocale locale () const
void setInputItemRectangle (const QRectF & rect )
void setInputItemTransform (const QTransform & transform )
void setVisible (bool visible )

公共槽

void commit ()
void hide ()
void invokeAction (QInputMethod::Action a , int cursorPosition )
void reset ()
void show ()
void update (Qt::InputMethodQueries queries )

信号

void anchorRectangleChanged ()
void animatingChanged ()
void cursorRectangleChanged ()
void inputDirectionChanged (Qt::LayoutDirection newDirection )
void inputItemClipRectangleChanged ()
void keyboardRectangleChanged ()
void localeChanged ()
void visibleChanged ()

静态公共成员

QVariant queryFocusObject (Qt::InputMethodQuery query , const QVariant & argument )

详细描述

QInputMethod 用于集成平台文本输入法的文本编辑器,且更常见的是通过应用程序视图查询各种文本输入法的相关信息 (像:虚拟键盘可见性和键盘尺度)。

Qt Quick 还提供访问 QML 中的 QInputMethod 透过 Qt 全局对象 as Qt.inputMethod 特性。

成员类型文档编制

enum QInputMethod:: Action

指示由用户履行的动作种类。

常量 描述
QInputMethod::Click 0 正常点击/敲击
QInputMethod::ContextMenu 1 上下文菜单点击/敲击 (如:右键或敲击并保持)

另请参阅 invokeAction ().

特性文档编制

[read-only] anchorRectangle : const QRectF

输入项在窗口坐标中的锚点矩形。

Anchor rectangle is often used by various text editing controls like text prediction popups for following the text selection.

访问函数:

QRectF anchorRectangle () const

通知程序信号:

void anchorRectangleChanged ()

[read-only] animating : const bool

true 当打开 (或关闭) 虚拟键盘时。

动画为 false 当完全打开 (或关闭) 键盘时。当 animating is true and visibility is true 键盘正被打开。当 animating is true and visibility 为 false 键盘正被关闭。

访问函数:

bool isAnimating () const

通知程序信号:

void animatingChanged ()

[read-only] cursorRectangle : const QRectF

输入项在窗口坐标中的光标矩形。

Cursor rectangle is often used by various text editing controls like text prediction popups for following the text being typed.

访问函数:

QRectF cursorRectangle () const

通知程序信号:

void cursorRectangleChanged ()

[read-only] inputDirection : const Qt::LayoutDirection

当前输入方向。

访问函数:

Qt::LayoutDirection inputDirection () const

通知程序信号:

void inputDirectionChanged (Qt::LayoutDirection newDirection )

[read-only] inputItemClipRectangle : const QRectF

输入项在窗口坐标中的裁剪矩形。

The clipped input rectangle is often used by various input methods to determine how much screen real estate is available for the input method (e.g. Virtual Keyboard).

访问函数:

QRectF inputItemClipRectangle () const

通知程序信号:

void inputItemClipRectangleChanged ()

[read-only] keyboardRectangle : const QRectF

虚拟键盘在窗口坐标中的几何体。

This might be an empty rectangle if it is not possible to know the geometry of the keyboard. This is the case for a floating keyboard on android.

访问函数:

QRectF keyboardRectangle () const

通知程序信号:

void keyboardRectangleChanged ()

[read-only] locale : const QLocale

当前输入区域设置。

访问函数:

QLocale locale () const

通知程序信号:

void localeChanged ()

[read-only] visible : const bool

虚拟键盘在屏幕上的可见性

Input method visibility remains false for devices with no virtual keyboards.

访问函数:

bool isVisible () const

通知程序信号:

void visibleChanged ()

另请参阅 show () 和 hide ().

成员函数文档编制

[slot] void QInputMethod:: commit ()

Commits the word user is currently composing to the editor. The function is mostly needed by the input methods with text prediction features and by the methods where the script used for typing characters is different from the script that actually gets appended to the editor. Any kind of action that interrupts the text composing needs to flush the composing state by calling the commit() function, for example when the cursor is moved elsewhere.

[slot] void QInputMethod:: hide ()

请求关闭虚拟键盘。

Normally applications should not need to call this function, keyboard should automatically close when the text editor loses focus, for example when the parent view is closed.

[slot] void QInputMethod:: invokeAction ( QInputMethod::Action a , int cursorPosition )

Called by the input item when the word currently being composed is tapped by the user, as indicated by the action a 和给定 cursorPosition . Input methods often use this information to offer more word suggestions to the user.

[slot] void QInputMethod:: reset ()

Resets the input method state. For example, a text editor normally calls this method before inserting a text to make widget ready to accept a text.

输入法自动重置,当聚焦编辑器改变时。

[slot] void QInputMethod:: show ()

请求打开虚拟键盘。若平台不提供虚拟键盘,可见性仍然为 false。

Normally applications should not need to call this function, keyboard should automatically open when the text editor gains focus.

[slot] void QInputMethod:: update ( Qt::InputMethodQueries queries )

Called by the input item to inform the platform input methods when there has been state changes in editor's input method query attributes. When calling the function queries parameter has to be used to tell what has changes, which input method can use to make queries for attributes it's interested with QInputMethodQueryEvent .

In particular calling update whenever the cursor position changes is important as that often causes other query attributes like surrounding text and text selection to change as well. The attributes that often change together with cursor position have been grouped in Qt::ImQueryInput value for convenience.

[since 5.1] QRectF QInputMethod:: inputItemRectangle () const

返回在输入项坐标中的输入项几何体。

该函数在 Qt 5.1 引入。

另请参阅 setInputItemRectangle ().

QTransform QInputMethod:: inputItemTransform () const

返回从输入项坐标到窗口坐标的变换。

另请参阅 setInputItemTransform ().

[static] QVariant QInputMethod:: queryFocusObject ( Qt::InputMethodQuery query , const QVariant & argument )

发送 query 到当前聚焦对象采用参数 argument 并返回结果。

[since 5.1] void QInputMethod:: setInputItemRectangle (const QRectF & rect )

把输入项的几何体设为 rect , in input item coordinates. This needs to be updated by the focused window like QQuickCanvas whenever item is moved inside the scene, or focus is changed.

该函数在 Qt 5.1 引入。

另请参阅 inputItemRectangle ().

void QInputMethod:: setInputItemTransform (const QTransform & transform )

Sets the transformation from input item coordinates to window coordinates to be transform . Item transform needs to be updated by the focused window like QQuickCanvas whenever item is moved inside the scene.

另请参阅 inputItemTransform ().

void QInputMethod:: setVisible ( bool visible )

控制键盘的可见性。相当于调用 show () (若 visible is true ) 或 hide () (若 visible is false ).

另请参阅 isVisible (), show (),和 hide ().