Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QInputMethodEvent Class Reference

The QInputMethodEvent class provides parameters for input method events. More...

    #include <QInputMethodEvent>

Inherits QInputEvent.

- List of all members, including inherited members

### Writable Properties

- 1 writable property inherited from QEvent

### Public Functions

- QInputMethodEvent ( Type type, const QString & text, int cursorPosition, int selLength = 0 )
- ~QInputMethodEvent ()
- int cursorPos () const
- int selectionLength () const
- const QString & text () const

- 1 public function inherited from QInputEvent
- 4 public functions inherited from QEvent

## Detailed Description

The QInputMethodEvent class provides parameters for input method events.

Input method events are sent to widgets when an input method is used to enter text into a widget. Input methods are widely used to enter text for languages with non-Latin alphabets.

The events are of interest to authors of keyboard entry widgets who want to be able to correctly handle languages with complex character input. Text input in such languages is usually a three step process.

1. <b>Starting to Compose</b><br> When the user presses the first key on a keyboard, an input context is created. This input context will contain a string of the typed characters.
2. <b>Composing</b><br> With every new key pressed, the input method will try to create a matching string for the text typed so far. While the input context is active, the user can only move the cursor inside the string belonging to this input context.
3. <b>Completing</b><br> At some point, the user will activate a user interface component (perhaps using a particular key) where they can choose from a number of strings matching the text they have typed so far. The user can either confirm their choice cancel the input; in either case the input context will be closed.

These three stages are represented by three different types of events: InputMethodStart, InputMethodCompose, and InputMethodEnd. All of these events are delivered to the imEvent() method. When a new input context is created, an InputMethodStart event will be sent to the widget. The widget can then update internal data structures to reflect this.

After this, an InputMethodCompose event will be sent to the widget for every key the user presses. It will contain the current composition string the widget has to show and the current cursor position within the composition string. This string is temporary and can change with every key the user types, so the widget will need to store the state before the composition started (the state it had when it received the InputMethodStart event).

Usually, widgets try to mark the part of the text that is part of the current composition in a way that is visible to the user. A commonly used visual cue is to use a dotted underline.

After the user has selected the final string, an InputMethodEnd event will be sent to the widget. The event contains the final string the user selected, and could be empty if they canceled the composition. This string should be accepted as the final text the user entered, and the intermediate composition string should be cleared.

If the user clicks another widget, taking the focus out of the widget where the composition is taking place, the InputMethodEnd event will be sent and the string it holds will be the result of the composition up to that point (which may be an empty string).

## Member Function Documentation

### QInputMethodEvent::QInputMethodEvent ( Type type, const QString & text, int cursorPosition, int selLength = 0 )

Constructs a new QInputMethodEvent with the accept flag set to false. The event type can be QEvent::InputMethodStart, QEvent::InputMethodCompose, or QEvent::InputMethodEnd. The text contains the current compostion string, and cursorPosition is the current position of the cursor inside the text. selLength characters are selected (default is 0).

### QInputMethodEvent::~QInputMethodEvent ()

### int QInputMethodEvent::cursorPos () const

Returns the current cursor position inside the composition string. Will return -1 for InputMethodStart event and InputMethodEnd event.

### int QInputMethodEvent::selectionLength () const

Returns the number of characters in the composition string, starting at cursorPos(), that should be marked as selected by the input widget receiving the event. Will return 0 for InputMethodStart event and InputMethodEnd event.

### const QString & QInputMethodEvent::text () const

Returns the composition text. This is a null string for an InputMethodStart event, and contains the final accepted string (which may be empty) in the InputMethodEnd event.