A Qt Quick TextField backed by an <input>
Qt for WebAssembly draws a TextField as pixels and takes typing through one hidden input element that it shares between all its fields.
This page loads a Qt Quick 6.10 app with three pairs of fields. In each pair the first is Qt's own TextField. The second is a QML component
with the same background and focus border, whose text, caret and selection are a real <input> drawn into Qt's scene.
Load the app, tap each field and type. The tables and logs under the app record what the browser was given for each field.
Qt Quick 6.10 for WebAssembly. It isn't loaded until you ask.
The app isn't loaded.
Show the code a QML text field that is an input element
- The inputs. Each has the
type,nameandautocompletethat a form on a web page would give it. - QML:
DomTextField. Qt draws the background and border of the Basic style'sTextField. ADomItemfills it. - QML: the window. A
Labeland aButtonbind totextof both kinds of field in the same way. - C++: the two-way
textproperty, focus and Tab. - JavaScript inside the C++ file: read and write the value, focus the input.
- Move the input into Qt's canvas and send its focus, blur and Tab key to the item.
- Stop Qt taking focus back.
- Copy the input's picture into a texture that Qt Quick's scene graph draws.
- Tell the browser where Qt drew the item.
- Start Qt and load a stylesheet for the inputs inside Qt's shadow root.
- CSS for the inputs.
- The event log. Listeners in the capture phase on
window. - All of domitem.cpp.
What the browser is given for each field
The page writes these from real events. A password field's keys and text are logged as lengths only. On a phone: tap a field, wait for the keyboard, type a few characters with a Japanese, Chinese or Korean keyboard if you have one, and look for an autofill suggestion above the keyboard. Then tap "Copy the log".
Qt TextField: the element Qt focuses
| element | Tap a Qt TextField. |
|---|
DomTextField: the focused <input>
| element | Tap a DomTextField. |
|---|
How it works
Qt Quick renders the window into one WebGL canvas, which Qt creates inside a shadow root. DomItem is a QQuickItem written for
/native-ui/. It moves an element into that canvas, copies the element's picture into a texture with
gl.texElementSubImage2D() on each paint event, and passes the item's matrix to canvas.updateElementGeometry(), so the
browser's box for the element is where Qt drew it. The browser handles taps, keys, composition and autofill on the element as it does for any input.
DomTextField.qml is the Basic style's TextField background (a Rectangle with a 1 px border, 2 px in the highlight colour
when focused) with a DomItem inside it. The copy of DomItem on this page adds three things. Its text property reads
element.value on every input event and assigns it when QML writes the property. Its domFocus property follows the
element's focus and blur events. It handles the Tab key in the element by asking Qt for nextItemInFocusChain(), and it
focuses the element when Qt's own Tab reaches the item.
Qt's own TextField has no element where it is drawn. When one gets focus, Qt focuses a hidden
<input class="qt-window-input-element"> that it keeps at the top left corner of the window, and turns that element's events into Qt key and
input method events. The page's log listens in the capture phase on window, so it records the events for both kinds of field before Qt or
DomItem handle them.
Live checks
The checks load a second copy of the app (23 MB) in a small frame, so they don't touch the one above. In that frame focus() is recorded and not run, so the checks read which element Qt would focus without moving focus on this page.
| Result | Experiment | Detail |
|---|
Findings
- The rest of the QML UI binds to the input like a
TextField.DomTextField.textis a two-way property. ALabelshows "Hello, " and the text, aButtonis enabled when two fields aren't empty, and the button's handler clears a field by assigningtext. All three work for both kinds of field. Measured in Chromium 157 on 2026-11-21. - Qt gives the browser a keyboard hint and nothing for autofill. Qt 6.10.3 focuses one
<input class="qt-window-input-element" type="text">for everyTextField. It setsinputmode="email"forQt.ImhEmailCharactersOnly,inputmode="numeric"forQt.ImhDigitsOnlyandtype="password"forechoMode: TextInput.Password. The element has noautocomplete,name,idor label, and QML'sTextFieldhas no property that would set one. The DOM fields havetype,nameandautocomplete(email,current-password,one-time-code). - Not verified: whether Chrome on Android offers autofill for either field. Headless Chromium has no saved addresses, passwords or text messages. On the phone, tap each DOM field and each Qt field and look for a suggestion above the keyboard or a popup at the field. The log writes a line when an element starts to match
:autofill. - Qt's hidden input isn't at the field. Its box is 9 by 7 px at the top left corner of the Qt window for all three fields: 62, 207 and 354 px from the caret that Qt drew. The browser places an IME candidate window and an autofill popup from the focused element's box, and scrolls that box into view when the keyboard opens. A DOM field's box is 0 px from where Qt drew it.
- Composition events reach both fields, and Qt's
TextFieldlost typed text. A composition sent with the DevTools protocol (Input.imeSetCompositionwith "に", "にほ", "にほん", thenInput.insertTextwith "日本") fired the samecompositionstart,compositionupdate,beforeinput,inputandcompositionendevents on both elements. In an empty Qt field the result was "日本". In a Qt field that held "abcd" each update deleted typed characters: "bcd", "d", then nothing, and the field ended as "日本". The DOM field ended as "abcd日本". Not verified with a real IME. - Qt's hidden input doesn't hold the field's text. After "abcd" was typed in a Qt field the hidden input's
valuewas empty. During a composition it held only the composition string. So the keyboard isn't given the text around the caret. - Text that is being composed is drawn in both fields. Qt draws its
preeditTextunderlined and keepstextunchanged until the commit. The DOM field'svalueincludes the composition string, soDomTextField.textand the label bound to it change during composition. The picture of the DOM field in Qt's scene had no composition underline. - Qt's font has no Japanese glyphs. Qt drew "にほん" and "日本" as empty boxes with its bundled DejaVu Sans. The DOM field drew them with the browser's fallback font.
- A tap places the caret in both. Two taps select a word only in the DOM field. Scripted touch taps, Chromium 157. In the DOM field a tap past the end of the text didn't clear a selection of the whole value, which it does in a plain input outside a canvas. The cause wasn't identified.
- Tab walks all six fields in order, in both directions.
document.activeElementis the shadow host. Inside the shadow root the active element alternates between Qt's hidden input and the DOM input. This needs the Tab handling inDomItem. - Qt takes browser focus away unless stopped. When a Qt item that takes no text gets Qt's active focus, Qt 6.10.3 calls
focus()on a hiddendiv.qt-window-focus-helper. That blurred the DOM input as soon as itsDomItemtook Qt's focus.DomItemreplaces that element'sfocus()with a function that does nothing while aDomItemhas Qt's focus. - A stylesheet in Qt's shadow root styles the inputs.
start.jsappends a<link rel="stylesheet">to the shadow root.::placeholderand::selectionrules apply, which inline styles couldn't do. - Cost: 23 MB. The WebAssembly file is 23.4 MB before compression, so the app loads after a tap.
Source: native/qt-textfield. The binary is statically linked against the open-source edition of Qt 6.10.3 (LGPL-3.0 and GPL-3.0). Its complete source is that folder plus Qt from download.qt.io.