QInputMethod Class

The QInputMethod class provides access to the active text input method. 更多...

头文件: #include <QInputMethod>
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)
  • 32 个公有函数继承自 QObject

公有槽函数

void commit()
void hide()
void invokeAction(Action a, int cursorPosition)
void reset()
void show()
void update(Qt::InputMethodQueries queries)
  • 1 个公有槽函数继承自 QObject

信号

静态公有成员

QVariant queryFocusObject(Qt::InputMethodQuery query, QVariant argument)
  • 10 个静态公有成员继承自 QObject

其他继承的成员

  • 1 个公有变量继承自 QObject
  • 9 个受保护的函数继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

The QInputMethod class provides access to the active text input method.

QInputMethod is used by the text editors for integrating to the platform text input methods and more commonly by application views for querying various text input method-related information like virtual keyboard visibility and keyboard dimensions.

Qt Quick also provides access to QInputMethod in QML through Qt global object as Qt.inputMethod property.

成员类型

enum QInputMethod::Action

Indicates the kind of action performed by the user.

ConstantValueDescription
QInputMethod::Click0A normal click/tap
QInputMethod::ContextMenu1A context menu click/tap (e.g. right-button or tap-and-hold)

参见 invokeAction().

属性

anchorRectangle : const QRectF

Input item's anchor rectangle in window coordinates.

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

访问函数:

QRectF anchorRectangle() const

Notifier signal:

void anchorRectangleChanged()

animating : const bool

True when the virtual keyboard is being opened or closed.

Animating is false when keyboard is fully open or closed. When animating is true and visibility is true keyboard is being opened. When animating is true and visibility is false keyboard is being closed.

访问函数:

bool isAnimating() const

Notifier signal:

void animatingChanged()

cursorRectangle : const QRectF

Input item's cursor rectangle in window coordinates.

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

访问函数:

QRectF cursorRectangle() const

Notifier signal:

void cursorRectangleChanged()

inputDirection : const Qt::LayoutDirection

Current input direction.

访问函数:

Qt::LayoutDirection inputDirection() const

Notifier signal:

void inputDirectionChanged(Qt::LayoutDirection newDirection)

inputItemClipRectangle : const QRectF

Input item's clipped rectangle in window coordinates.

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

Notifier signal:

void inputItemClipRectangleChanged()

keyboardRectangle : const QRectF

Virtual keyboard's geometry in window coordinates.

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

Notifier signal:

void keyboardRectangleChanged()

locale : const QLocale

Current input locale.

访问函数:

QLocale locale() const

Notifier signal:

void localeChanged()

visible : const bool

Virtual keyboard's visibility on the screen

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

访问函数:

bool isVisible() const

Notifier signal:

void visibleChanged()

参见 show() and 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()

Requests virtual keyboard to close.

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.

QRectF QInputMethod::inputItemRectangle() const

Returns the input item's geometry in input item coordinates.

This function was introduced in Qt 5.1.

参见 setInputItemRectangle().

QTransform QInputMethod::inputItemTransform() const

Returns the transformation from input item coordinates to the window coordinates.

参见 setInputItemTransform().

[slot] void QInputMethod::invokeAction(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 and the given cursorPosition. Input methods often use this information to offer more word suggestions to the user.

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

Send query to the current focus object with parameters argument and return the result.

[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.

Input method resets automatically when the focused editor changes.

void QInputMethod::setInputItemRectangle(const QRectF &rect)

Sets the input item's geometry to be 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.

This function was introduced in 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)

Controls the keyboard visibility. Equivalent to calling show() (if visible is true) or hide() (if visible is false).

参见 isVisible(), show(), and hide().

[slot] void QInputMethod::show()

Requests virtual keyboard to open. If the platform doesn't provide virtual keyboard the visibility remains 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.