DOM elements in a Qt Widgets window

Qt Quick renders with WebGL, and an earlier page gave it DOM elements as textures. Qt Widgets, the older and more widely used Qt toolkit, paints every window in software and copies the changed pixels to a 2D canvas with putImageData(). This page loads a Qt Widgets 6.10 app and draws real elements into the window's canvas with drawElementImage() after each of those copies. Load the app, then tap a field to type, scroll the window, move the slider, or open the Qt combo box above the fields.

DOM text with a link: مرحبا, 你好, 👋🏽.

Qt 6.10 for WebAssembly. It isn't loaded until you ask.

The app isn't loaded.

Show the code a DOM element in a Qt Widgets layout
  1. The elements. They start outside Qt's canvas, which doesn't exist yet.
  2. C++: the window. A DomWidget is added to a QVBoxLayout like any widget.
  3. C++: the widget. It paints a background and reports its rectangle and its visible part.
  4. JavaScript inside the C++ file: draw after Qt's flush. putImageData() on Qt's context is wrapped.
  5. Move the elements into Qt's canvas and ask Qt to repaint a widget when the browser repaints its element.
  6. Record where the widget is.
  7. Start Qt.
  8. CSS for the elements.
  9. All of domwidget.cpp.

Live checks

The checks load a second copy of the app (14 MB) in a small frame, so they don't touch the one above.

ResultExperimentDetail

Findings

Source: native/qt-widgets-dom. 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.