- Qt 6.5
- Qt Virtual Keyboard
- C++ Classes
- QVirtualKeyboardAbstractInputMethod
- Qt Virtual Keyboard | Commercial or GPLv3

# QVirtualKeyboardAbstractInputMethod Class

The base class for input methods. More...

Header: | #include <QVirtualKeyboardAbstractInputMethod>
CMake: | find_package(Qt6 REQUIRED COMPONENTS VirtualKeyboard) target_link_libraries(mytarget PRIVATE Qt6::VirtualKeyboard)
qmake: | QT += virtualkeyboard
Inherits: | QObject

- List of all members, including inherited members

## Public Functions

| QVirtualKeyboardAbstractInputMethod(QObject *parent = nullptr)
virtual | ~QVirtualKeyboardAbstractInputMethod()
virtual bool | clickPreeditText(int cursorPosition)
QVirtualKeyboardInputContext * | inputContext() const
QVirtualKeyboardInputEngine * | inputEngine() const
virtual QList<QVirtualKeyboardInputEngine::InputMode> | inputModes(const QString &locale) = 0
virtual bool | keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers) = 0
virtual QList<QVirtualKeyboardInputEngine::PatternRecognitionMode> | patternRecognitionModes() const
virtual bool | reselect(int cursorPosition, const QVirtualKeyboardInputEngine::ReselectFlags &reselectFlags)
virtual QVariant | selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, QVirtualKeyboardSelectionListModel::Role role)
virtual int | selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type)
virtual void | selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index)
virtual bool | selectionListRemoveItem(QVirtualKeyboardSelectionListModel::Type type, int index)
virtual QList<QVirtualKeyboardSelectionListModel::Type> | selectionLists()
virtual bool | setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode) = 0
virtual bool | setTextCase(QVirtualKeyboardInputEngine::TextCase textCase) = 0
virtual QVirtualKeyboardTrace * | traceBegin(int traceId, QVirtualKeyboardInputEngine::PatternRecognitionMode patternRecognitionMode, const QVariantMap &traceCaptureDeviceInfo, const QVariantMap &traceScreenInfo)
virtual bool | traceEnd(QVirtualKeyboardTrace *trace)

## Public Slots

virtual void | clearInputMode()
virtual void | reset()
virtual void | update()

## Signals

void | selectionListActiveItemChanged(QVirtualKeyboardSelectionListModel::Type type, int index)
void | selectionListChanged(QVirtualKeyboardSelectionListModel::Type type)
void | selectionListsChanged()

## Detailed Description

Use this class if you want to implement a custom input method using C/C++ language.

## Member Function Documentation

### `[explicit]` QVirtualKeyboardAbstractInputMethod::QVirtualKeyboardAbstractInputMethod(QObject *parent = nullptr)

Constructs an input method with parent.

### `[virtual]` QVirtualKeyboardAbstractInputMethod::~QVirtualKeyboardAbstractInputMethod()

Destroys the input method and frees all allocated resources.

### `[virtual slot, since QtQuick.VirtualKeyboard 6.1]` void QVirtualKeyboardAbstractInputMethod::clearInputMode()

Clears input mode.

This method is called by the virtual keyboard when this input method is being replaced by another input method. It should clear the operations performed by setInputMode() method, for example, to disconnect signal handlers from the virtual keyboard or free up resources.

The input mode may be reactivated by calling setInputMode(). However, note that the calls to setInputMethod() and clearInputMethod() are not in balance. Thus, for example, setInputMethod() may be called multiple times without matching calls to clearInputMethod().

The default implementation does nothing.

This function was introduced in QtQuick.VirtualKeyboard 6.1.

### `[virtual, since QtQuick.VirtualKeyboard 2.4]` bool QVirtualKeyboardAbstractInputMethod::clickPreeditText(int cursorPosition)

Called when the user clicks on pre-edit text at cursorPosition.

The function should return `true` if it handles the event. Otherwise the input falls back to reselect() for further processing.

This function was introduced in QtQuick.VirtualKeyboard 2.4.

### QVirtualKeyboardInputContext *QVirtualKeyboardAbstractInputMethod::inputContext() const

Returns the input context associated with the input method. This method returns `NULL` if the input method is not active.

### QVirtualKeyboardInputEngine *QVirtualKeyboardAbstractInputMethod::inputEngine() const

Returns the input engine associated with the input method. This method returns `NULL` if the input method is not active.

### `[pure virtual]` QList<QVirtualKeyboardInputEngine::InputMode> QVirtualKeyboardAbstractInputMethod::inputModes(const QString &locale)

Returns the list of input modes for locale.

### `[pure virtual]` bool QVirtualKeyboardAbstractInputMethod::keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers)

The purpose of this method is to handle the key events generated by the the input engine.

The key parameter specifies the code of the key to handle. The key code does not distinguish between capital and non-capital letters. The text parameter contains the Unicode text for the key. The modifiers parameter contains the key modifiers that apply to key.

This method returns `true` if the key event was successfully handled. If the return value is `false`, the key event is redirected to the default input method for further processing.

### `[virtual, since QtQuick.VirtualKeyboard 2.0]` QList<QVirtualKeyboardInputEngine::PatternRecognitionMode> QVirtualKeyboardAbstractInputMethod::patternRecognitionModes() const

Returns list of supported pattern recognition modes.

This method is called by the input engine to query the list of supported pattern recognition modes.

This function was introduced in QtQuick.VirtualKeyboard 2.0.

### `[virtual, since QtQuick.VirtualKeyboard 2.0]` bool QVirtualKeyboardAbstractInputMethod::reselect(int cursorPosition, const QVirtualKeyboardInputEngine::ReselectFlags &reselectFlags)

This function attempts to reselect a word located at the cursorPosition. The reselectFlags define the rules for how the word should be selected in relation to the cursor position.

The function returns `true` if the word was successfully reselected.

This function was introduced in QtQuick.VirtualKeyboard 2.0.

### `[virtual slot]` void QVirtualKeyboardAbstractInputMethod::reset()

This method is called by the input engine when the input method needs to be reset. The input method must reset its internal state only. The main difference to the update() method is that reset() modifies only the input method state, i.e. it must not modify the input context.

### `[signal]` void QVirtualKeyboardAbstractInputMethod::selectionListActiveItemChanged(QVirtualKeyboardSelectionListModel::Type type, int index)

The input method emits this signal when the current index has changed in the selection list identified by type.

### `[signal]` void QVirtualKeyboardAbstractInputMethod::selectionListChanged(QVirtualKeyboardSelectionListModel::Type type)

The input method emits this signal when the contents of the selection list has changed. The type parameter specifies which selection list has changed.

### `[virtual]` QVariant QVirtualKeyboardAbstractInputMethod::selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, QVirtualKeyboardSelectionListModel::Role role)

Returns item data for the selection list identified by type. The role parameter specifies which data is requested. The index parameter is a zero based index into the list.

### `[virtual]` int QVirtualKeyboardAbstractInputMethod::selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type)

Returns the number of items in the selection list identified by type.

### `[virtual]` void QVirtualKeyboardAbstractInputMethod::selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index)

This method is called when an item at index has been selected by the user. The selection list is identified by the type parameter.

### `[virtual]` bool QVirtualKeyboardAbstractInputMethod::selectionListRemoveItem(QVirtualKeyboardSelectionListModel::Type type, int index)

This method is called when an item at index must be removed from dictionary. The selection list is identified by the type parameter. The function returns `true` if the word was successfully removed.

### `[virtual]` QList<QVirtualKeyboardSelectionListModel::Type> QVirtualKeyboardAbstractInputMethod::selectionLists()

Returns the list of selection lists used by this input method.

This method is called by input engine when the input method is being activated and every time the input method hints are updated. The input method can reserve selection lists by returning the desired selection list types.

The input method may request the input engine to update the selection lists at any time by emitting selectionListsChanged() signal. This signal will trigger a call to this method, allowing the input method to update the selection list types.

### `[signal, since QtQuick.VirtualKeyboard 2.2]` void QVirtualKeyboardAbstractInputMethod::selectionListsChanged()

The input method emits this signal when the selection list types have changed. This signal will trigger a call to selectionLists() method, allowing the input method to update the selection list types.

This function was introduced in QtQuick.VirtualKeyboard 2.2.

### `[pure virtual]` bool QVirtualKeyboardAbstractInputMethod::setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode)

Sets the inputMode and locale for this input method. Returns `true` if successful.

### `[pure virtual]` bool QVirtualKeyboardAbstractInputMethod::setTextCase(QVirtualKeyboardInputEngine::TextCase textCase)

Updates the textCase for this input method. The method returns `true` if successful.

### `[virtual, since QtQuick.VirtualKeyboard 2.0]` QVirtualKeyboardTrace *QVirtualKeyboardAbstractInputMethod::traceBegin(int traceId, QVirtualKeyboardInputEngine::PatternRecognitionMode patternRecognitionMode, const QVariantMap &traceCaptureDeviceInfo, const QVariantMap &traceScreenInfo)

This method is called when a trace interaction starts with the specified patternRecognitionMode. The trace is uniquely identified by the traceId. The traceCaptureDeviceInfo provides information about the source device and the traceScreenInfo provides information about the screen context.

If the input method accepts the event and wants to capture the trace input, it must return a new QVirtualKeyboardTrace object. This object must remain valid until the traceEnd() method is called. If the QVirtualKeyboardTrace is rendered on screen, it remains there until the QVirtualKeyboardTrace object is destroyed.

This function was introduced in QtQuick.VirtualKeyboard 2.0.

### `[virtual, since QtQuick.VirtualKeyboard 2.0]` bool QVirtualKeyboardAbstractInputMethod::traceEnd(QVirtualKeyboardTrace *trace)

This method is called when the trace interaction ends. The input method should destroy the trace object at some point after this function is called. See the Trace API for Input Methods how to access the gathered data.

The method returns `true` if the trace interaction is accepted.

This function was introduced in QtQuick.VirtualKeyboard 2.0.

### `[virtual slot]` void QVirtualKeyboardAbstractInputMethod::update()

This method is called by the input engine when the input method needs to be updated. The input method must close the current pre-edit text and restore its internal state to the default.