/qt-development-skills:qt-widgets-to-quickfrom qt-development-skills
Ports Qt Widgets applications (QWidget, QMainWindow, .ui files, QPainter paintEvent) to Qt Quick with QML, Qt Quick Controls, and QCanvasPainter for custom painting. Activates on migration or modernization requests.
Ships in qt-development-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Goal: turn a QtWidgets application into a Qt Quick application that looks and behaves the same, is idiomatic QML/C++, and builds cleanly.
| Widgets code | Becomes |
|---|---|
Widget UI, layouts, dialogs, menus, .ui | QML + Qt Quick Controls + Qt Quick Layouts |
Custom QWidget with paintEvent / QPainter | QCanvasPainterItem + QCanvasPainterItemRenderer using QCanvasPainter (Qt6::CanvasPainter, GPU, HTML-Canvas-like API) |
| Logic, models, I/O, networking, business classes | stays C++, exposed with QML_ELEMENT / QML_SINGLETON / Q_PROPERTY |
Do not answer API questions from memory. The references list the classes and
members that matter; for anything not listed, check the Qt docs (the qt-docs
MCP tools, if available) or the installed headers (include/QtCanvasPainter/).
styling.md is
mandatory for any port with a UI.qt-qml for the QML you write, qt-cmake-project when
restructuring CMake, and qt-canvas2d (its references/api-reference.md)
as a second source on painter semantics.| Need | Read |
|---|---|
| Which Controls type replaces a widget; event → handler mapping | references/widget-mapping.md |
| Layouts, size policies, stretch, splitters, scroll areas, form layouts | references/layouts.md |
QMainWindow, menus, toolbars, dialogs, actions, .ui, main.cpp | references/application-structure.md |
| C++ ↔ QML bridge, models, signals/slots | references/cpp-qml-integration.md |
| Style selection, palette, QSS, fonts, icons, High-DPI | references/styling.md |
QPainter / paintEvent code | references/painting-qpainter-to-canvaspainter.md, references/custom-painted-items.md |
| CMake | references/cmake.md |
| Large or multi-window app, staged port, modal prompts, export, tests | references/large-app-porting.md |
QGraphicsScene as the document model, or QGraphicsView with many simple items | references/graphics-view-to-canvaspainter.md |
| Many items per frame, slower than the original, benchmarking | references/performance.md |
| Worked before/after projects | examples/ (bottom of this file) |
Grep and write a short table (in your reasoning or the reply):
QWidget|QMainWindow|QDialog|QFrame|Q\w+(Edit|Box|Button|View|Widget|Bar|Menu|Label);
.ui files; .qss / setStyleSheet.paintEvent|QPainter|drawText|drawPixmap|QGraphicsView|QGraphicsScene|QOpenGLWidget
(QOpenGLWidget is not covered by QCanvasPainter; see "Hard cases").mousePressEvent|keyPressEvent|wheelEvent|eventFilter|dragEnterEvent|contextMenuEvent|resizeEvent.QAbstractItemModel|QStandardItemModel|QSortFilterProxyModel|QStyledItemDelegate
(usually reusable unchanged).QTimer|QThread|QSettings|QTranslator|tr(.exec(), QMessageBox, QFileDialog, QInputDialog.setAttribute\(Qt::AA_|setNativeMenuBar
(e.g. AA_DontUseNativeMenuBar keeps menus in the window on macOS).QT_VERSION_STR|_VERSION\b|__DATE__ (QML
cannot see them; pass them from C++, application-structure.md).QAction|addAction|QShortcut|setShortcut|QKeySequence
in C++, and <action name=…> / <addaction / <property name="shortcut">
in .ui files. Write one row per action: text, shortcut (literal or
StandardKey), where it appears (menu, toolbar, context menu, or shortcut
only), and the slot it triggers. Actions added only to the window
(addAction(act) with no menu) are easy to miss.QMainWindow the
features are its slots (toUpperCase(), insertDate(), nextTab(), …).
Every slot reached from the action table is a feature that must exist in the
port, even though the class itself disappears.Classify each UI class:
| Code | Target |
|---|---|
| Layout/composition of standard widgets | QML + Controls |
Custom widget painting with QPainter | QCanvasPainterItem (C++) |
| Custom widget that only composes other widgets | reusable QML component |
| Non-UI logic (data, parsing, I/O, state machines) | keep as C++ QObject, expose to QML |
| Models | keep, use from QML views |
myapp/
CMakeLists.txt
main.cpp # QGuiApplication + QQmlApplicationEngine
Main.qml # was MainWindow
qtquickcontrols2.conf # style selection (styling.md)
components/*.qml # one per composed widget / dialog
backend/*.h|cpp # former non-UI C++ (QML_ELEMENT / QML_SINGLETON)
items/*.h|cpp # QCanvasPainterItem + renderer pairs
qt_add_qml_module for the app: C++ types in SOURCES, QML in
QML_FILES; QML_ELEMENT types then register automatically.engine.loadFromModule("<Uri>", "Main") plus the
objectCreationFailed → exit(-1) guard (examples/*/main.cpp).AnalogClock), but never reuse the
name of a built-in Controls type.QApplication → QGuiApplication; drop widget includes; QMainWindow →
ApplicationWindow (menuBar, header = ToolBar, footer = status bar).
Keep every setAttribute(Qt::AA_…) call; macros used in UI text
(QT_VERSION_STR) go to QML as an initial property or singleton property.
See references/application-structure.md.
Use widget-mapping.md and layouts.md. Habits:
qtquickcontrols2.conf and add it to CMake, mirroring the
original: the style it set, or, if it set none, the platform default plus a
+windows/qtquickcontrols2.conf with Style=FluentWinUI3 (Qt Quick's
default Windows style does not match the Widgets windows11 style). State
the choice in the report; no need to ask first (styling.md).QtQuick, QtQuick.Controls, QtQuick.Layouts. Never import
a style module (QtQuick.Controls.Universal, .Material, …): it pins the
style at compile time.Layout.fillWidth, Layout.preferredWidth, …, never bare
width: / anchors (see qt-qml).&File), wrapped in
qsTr(). Preserve tab order, default values, ranges, tooltips, enabled and
visible state.ListView
starts at row 0 but QListWidget has no current row (currentIndex: -1);
date/time text uses the widget's format, by default the locale's short
format, never raw ISO ("Default state differences" in widget-mapping.md).setContentsMargins / spacing → Layout.margins, spacing,
columnSpacing, rowSpacing; the outermost layout's margins go on the
window content item.QLineEdit → TextField; QTextEdit → ScrollView { TextArea {} }.
Fusion, FluentWinUI3 and the native styles draw a frame for TextArea
themselves; only Basic draws none. Add a background only for a style
that lacks one, and never under Windows/macOS (not customizable; it
prints a warning).QML_ELEMENT (instantiable), QML_SINGLETON
(global service) or QML_UNCREATABLE (C++-provided).QMainWindow/QDialog, go through its slots (the feature list
from step 1) and split each one: the widget-touching part (read selection,
insert text, switch tab) becomes QML; the computation (case conversion, date
formatting from settings, parsing, file handling) moves to a backend
QObject as a Q_INVOKABLE that takes and returns plain values
(QString toUpperCase(const QString &text)). Trivial one-liners may stay in
QML JS. A slot you deliberately leave out goes into the report, never
silently (large-app-porting.md, "Extract a widget-free controller first").connect(button, &QPushButton::clicked, …) with onClicked calling a
Q_INVOKABLE/slot, or with a binding to a Q_PROPERTY. C++ must not hold
pointers to QML items: C++ emits signals or changes properties, QML reacts.QAbstractItemModel subclasses are reused as-is by ListView, TableView,
TreeView (cpp-qml-integration.md).Q_INVOKABLEs into the QML engine:
catch and report via return value or signal (large-app-porting.md).For every paintEvent:
Foo : QCanvasPainterItem (GUI thread: QML_ELEMENT, Q_PROPERTYs, input,
update()) plus FooRenderer : QCanvasPainterItemRenderer (render thread:
paint()); createItemRenderer() returns the renderer.synchronizeData(), the only point where both threads are synchronized.
paint() must not touch the item.QPainter calls with painting-qpainter-to-canvaspainter.md.
Traps: rotation in radians (not for setTransform(QTransform)); fill
and stroke are explicit (no pen/brush state); path first; ellipse()
takes centre + radii; fillColor clears the background every frame; images
via addImage once, drawImage per frame.
Redrawing every item every frame can be slower than the original's dirty
region repaint once hundreds of items are visible: batch the drawing
(performance.md) and measure against the original before calling it done.custom-painted-items.md).QSS → Controls customization (styling.md); QIcon/.qrc →
qt_add_qml_module(RESOURCES …) + Image / icon.source; tr() → qsTr()
in QML (keep tr() in C++); .ts files keep working with
qt_add_translations.
In this order:
git archive <rev> into a scratch dir) and run
it beside the port. Some behavioural differences were found only that way,
not by reading code.CMAKE_PREFIX_PATH; Qt's bin on PATH when started from a
script). Fix every warning that is yours.qmllint (-I <build dir>) and qmlformat -i on all QML.is not a type, Cannot assign,
Binding loop or other QML error on stderr is a defect
(QT_FORCE_STDERR_LOGGING=1 for Windows GUI apps; QT_LOGGING_TO_CONSOLE
is deprecated in 6.12).QQuickWindow::grabWindow().save(...) from a throwaway harness; OS screen
captures (CopyFromScreen) also worked for GPU windows when unobscured. For
scripted input from outside, make the driver DPI-aware: with display
scaling a DPI-unaware script gets cursor coordinates in logical pixels while
screenshots are physical, and clicks land off target.QT_QPA_PLATFORM=windows:darkmode=0
gives light on a dark Windows). Painted items take colors from
palette.*; hard-coded light colors that were fine in Widgets need a
decision (follow the palette, or keep and mention).QT_LOGGING_RULES=qt.quick.mouse.debug=true.performance.md); QSG_RENDER_TIMING=1 gives polish/sync/render per frame.QtWidgets includes or Qt6::Widgets linkage remain unless the user
chose a hybrid port. Link Qt6::Quick; add Qt6::CanvasPainter only when a
QCanvasPainterItem ships (it pulls Widgets in transitively; that is fine,
see cmake.md).paint(), or call
into QML from the render thread.palette.* role
matches the widget's QPalette role.large-app-porting.md,
graphics-view-to-canvaspainter.md).Simple one-to-one widget replacements are in widget-mapping.md; these need a
decision.
| Source | Target |
|---|---|
QFormLayout | two-column GridLayout (labels column 0, fields Layout.fillWidth) |
QGraphicsView/Scene, display-like, few items | Qt Quick scene graph (items, Flickable, PinchHandler, DragHandler); custom item painting → QCanvasPainterItem |
QGraphicsView/Scene with many simple items (one item type, no hierarchy) | plain-value model + grid index + one QCanvasPainterItem per view, frame recorded in updatePolish(), batched drawing ("Light variant", performance.md) |
QGraphicsView/Scene/Item as an editor document (hundreds+ items, hierarchy, selection, drag, hover) | one QCanvasPainterItem + own model, spatial index and input dispatcher (graphics-view-to-canvaspainter.md) |
QGraphicsScene as document model under a Quick UI | works headless, but keeps Qt6::Widgets + QApplication; replace in stages |
QOpenGLWidget / QRhiWidget | QQuickRhiItem (or QQuickFramebufferObject for GL-only code) |
QTableWidget / QTreeWidget (item-based) | model (QStandardItemModel or custom) + TableView / TreeView |
QTableView + delegate painting hundreds of columns | one QCanvasPainterItem culling to the viewport, sharing a QItemSelectionModel (large-app-porting.md) |
QDockWidget, QMdiArea | SplitView / Drawer / separate Windows; docking UX must be rebuilt |
QCustomPlot / Qt Charts widgets | Qt Graphs (GraphsView) or a QCanvasPainterItem |
QSS :hover, gradients, custom controls | Controls background / contentItem customization |
QPainter clip paths | QCanvasPainter has only rectangular clip (setClipRect): fill the rounded shape instead, or pre-render |
QMessageBox::question / exec() deep in business code | split at the prompt: request signal + respond(id, answer) continuation via a dialog-service singleton and DialogHost.qml; headless default answer; no nested event loop (large-app-porting.md) |
QTableView::grab(), QPrinter PDF export | render the shared painter code to QImage / QPdfWriter (QtGui, no PrintSupport) |
findChild / objectName lookups (tours, spotlights) | attached-property registry (Thing.name: "x"), one overlay per window |
| Event-filter helper painting and hit-testing handles over a widget | QML handle items + DragHandler + Q_INVOKABLE geometry on the item (custom-painted-items.md) |
Widget Q_PROPERTYs named rotation, scale, width, … | rename; they clash with QQuickItem properties |
QApplication::font() / clipboard(), QToolTip::font() | QGuiApplication::font() / clipboard() |
Hybrid fallback for apps too large to port in one go: QCanvasPainterWidget
moves a custom-painted widget to QCanvasPainter without leaving QtWidgets, and
QQuickWidget embeds finished QML inside an unported Widgets window.
examples/ holds four buildable projects. The *_quick folders are the
quality bar: no dead code, no style-specific imports, behavior identical to the
original.
| Folder | Shows |
|---|---|
analogclock_widgets/ | Original: QWidget + QPainter + QTimer |
analogclock_quick/ | QCanvasPainterItem + renderer, synchronizeData, radians, palette colors |
basiclayouts_widgets/ | Original: group boxes, box/grid/form layouts, menu bar, scroll area |
basiclayouts_quick/ | ApplicationWindow, MenuBar, GroupBox, GridLayout, ScrollView, style via conf, small C++ backend |
examples/analogclock_quick/CMakeLists.txt (opens in a new tab)examples/analogclock_quick/Main.qml (opens in a new tab)examples/analogclock_quick/analogclock.cpp (opens in a new tab)examples/analogclock_quick/analogclock.h (opens in a new tab)examples/analogclock_quick/analogclockrenderer.cpp (opens in a new tab)examples/analogclock_quick/analogclockrenderer.h (opens in a new tab)examples/analogclock_quick/main.cpp (opens in a new tab)examples/analogclock_widgets/CMakeLists.txt (opens in a new tab)examples/analogclock_widgets/analogclock.cpp (opens in a new tab)examples/analogclock_widgets/analogclock.h (opens in a new tab)examples/analogclock_widgets/main.cpp (opens in a new tab)examples/basiclayouts_quick/CMakeLists.txt (opens in a new tab)examples/basiclayouts_quick/Main.qml (opens in a new tab)examples/basiclayouts_quick/appbackend.cpp (opens in a new tab)examples/basiclayouts_quick/appbackend.h (opens in a new tab)examples/basiclayouts_quick/main.cpp (opens in a new tab)examples/basiclayouts_quick/qtquickcontrols2.conf (opens in a new tab)examples/basiclayouts_widgets/CMakeLists.txt (opens in a new tab)examples/basiclayouts_widgets/main.cpp (opens in a new tab)examples/basiclayouts_widgets/mainwindow.cpp (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub theqtcompanyrnd/agent-skills --plugin qt-development-skills14 skills in this plugin
/qt-canvas2dApplies Qt Canvas2D (QtCanvas2D / Qt Canvas Painter, Qt 6.12+) best practices when producing or working with Canvas2D QML source code. Use whenever Canvas2D, Canvas2DContext, path2d, boxshadow2d, boxgradient2d, gridpattern2d, conicalgradient2d or transform2d is the subject: writing, reviewing, fixing, optimizing, or porting Qt Quick Canvas / HTML5 canvas drawing code to Canvas2D. Also use for GPU-accelerated imperative 2D drawing in QML — gauges, dials, charts, waveforms, oscilloscopes, clocks, freehand drawing — including choosing between Canvas2D and Shape/ShapePath when the renderer has not been decided yet. Do NOT trigger for plain Qt Quick Canvas work that must stay on the old CPU element, or for reviewing existing Shape/ShapePath code where the renderer is already settled./qt-cmake-projectUse to generate or update Qt 6 CMake projects or edit CMakeLists.txt, add sources/resources or define targets (executable, QML module, library)./qt-cpp-docsGenerates standalone Markdown reference documentation for any Qt/C++ source files — Qt Widgets classes, Qt Quick backends, Qt/C++ modules, plain C++ utilities, structs, free-function headers, and entry points like main.cpp. Use this skill to document any .h or .cpp file: Qt classes, plain C++ code, utility helpers, or application startup files. Triggers on: "document this class", "write docs for my C++", "document main.cpp", "C++ API docs", "document my Qt app", or whenever C++ or header files are provided and documentation is needed. Works with single files, pasted code, or entire project folders. DO NOT use if the user asks for QDoc format output.Other plugins' skills for the same job