TypePHP\Qt
Guide
Widgets
Advanced
Reference
FAQ
  • English
  • 简体中文
GitHub
Guide
Widgets
Advanced
Reference
FAQ
  • English
  • 简体中文
GitHub
  • Reference

    • Reference
    • CLI
    • API Reference
    • Packaging
    • Platform Support

API Reference

TypePHP\Qt\QtApp

Lifecycle

MethodDescription
create(array $options = []): voidInitialize QApplication (idempotent). $options supports name version organization font_size stylesheet
createWindow(string $title, array $options = []): mixedCreate a window. $options supports width height min_width min_height centered
run(int $maxFrames = 0): voidEnter the main loop until the window closes (or $maxFrames frames elapse)
runFrames(int $frames = 3): voidPump the given number of frames, then return. Use this for multiple windows
stop(): voidRequest the main loop to exit
close(): voidRequest the window to close
isOpen(): boolIs the window still open
destroy(): voidDestroy the window and release resources
handle(): mixedGet the underlying window handle

Describing the UI

MethodDescription
view(callable $builder): voidRegister the view builder. Runs every frame, returning a widget tree
render(array $tree): voidRender a tree directly (bypassing view()). Used for multiple windows
patch(array $ops): voidIncremental patch, see Patching

Events

MethodDescription
on(string $id, string $type, callable $handler): voidRegister by id + type
onAny(string $type, callable $handler): voidRegister by type only (no id, e.g. tray)
dispatch(array $event): voidDispatch an event manually (used by --selftest)

A handler may declare 0 or 1 parameters (array $event) — the framework probes the count at registration.

Reading widget values

MethodReturns
text(string $id): stringThe text of a text control
value(string $id): mixedThe value of a numeric / selection control
checked(string $id): boolThe checked state

Imperative operations (not in the widget tree, skipped by the diff)

MethodDescription
setTitle(string $title): voidWindow title
setMenu(array $items): voidMenu bar
setStatus(array $segments): voidStatus-bar segments
resize(int $width, int $height): voidWindow size
setTray(array $spec): voidSystem tray. $spec supports icon tooltip visible menu
setTimer(string $id, int $intervalMs): voidTimer; interval <= 0 stops it

Dialogs

MethodDescription
message(array $spec): stringLow-level message box; returns the pressed button
alert(string $text, string $title = '提示'): voidInformation box
error(string $text, string $title = '错误'): voidError box
confirm(string $text, string $title = '确认'): boolConfirmation box
openFile(string $title = '打开文件', string $filter = ''): arrayReturns ['path'=>…, 'name'=>…], or [] when cancelled
saveFile(string $title = '保存文件', string $filter = '', string $filename = ''): arrayAs above
pickDirectory(string $title = '选择目录'): stringReturns '' when cancelled
notify(string $title, string $message): voidSystem notification

Clipboard

MethodDescription
clipboardRead(): stringRead the clipboard
clipboardWrite(string $text): voidWrite the clipboard
webViewBackend(): string'webview2' / 'wkwebview' / 'textbrowser'
webViewSupportsJs(): boolWhether the compiled-in backend can run JavaScript
webViewReload(string $id): voidReload the webview (no-op on QTextBrowser)
webViewGoBack(string $id): voidGo back (no-op on QTextBrowser)
webViewGoForward(string $id): voidGo forward (no-op on QTextBrowser)

Verification and diagnostics

MethodDescription
headless(bool $on = true): voidHeadless mode: dialogs do not block
isHeadless(): boolWhether headless mode is on
snapshot(string $path): boolSave a PNG
frameCount(): intFrames rendered so far
lastError(): stringThe last handler exception (with file:line)
clearError(): voidClear the error

TypePHP\Qt\WidgetTree

All static factory methods returning array nodes. Signatures and main properties: Widget Catalog.

WidgetTree::vbox(array $children, array $props = [])
WidgetTree::hbox(array $children, array $props = [])
WidgetTree::grid(array $children, array $props = [])
WidgetTree::form(array $children, array $props = [])
WidgetTree::group(string $title, array $children, array $props = [])
WidgetTree::frame(array $children, array $props = [])
WidgetTree::scroll(array $children, array $props = [])
WidgetTree::tabs(array $pages, array $props = [])
WidgetTree::tab(string $title, array $children, array $props = [])
WidgetTree::stack(array $pages, array $props = [])
WidgetTree::page(array $children, array $props = [])
WidgetTree::split(array $children, array $props = [])
WidgetTree::spacer(int $size = 0, array $props = [])
WidgetTree::separator(array $props = [])

WidgetTree::label(string $text, array $props = [])
WidgetTree::image(string $path, array $props = [])
WidgetTree::link(string $text, string $href, array $props = [])
WidgetTree::button(string $text, array $props = [])
WidgetTree::lineEdit(string $text = '', array $props = [])
WidgetTree::textEdit(string $text = '', array $props = [])
WidgetTree::spin(int $value = 0, array $props = [])
WidgetTree::doubleSpin(float $value = 0.0, array $props = [])
WidgetTree::slider(int $value = 0, array $props = [])
WidgetTree::progress(int $value = 0, array $props = [])
WidgetTree::checkbox(string $text = '', bool $checked = false, array $props = [])
WidgetTree::radio(string $text = '', bool $checked = false, array $props = [])
WidgetTree::combo(array $items, string $value = '', array $props = [])
WidgetTree::list(array $items, string $value = '', array $props = [])
WidgetTree::table(array $columns, array $rows, array $props = [])
WidgetTree::tree(array $nodes, array $props = [])
WidgetTree::webView(string $url = '', array $props = [])
WidgetTree::html(string $html, array $props = [])

Event table

EventEmitted byvaluepayload
clickbutton, linkthe link's href—
changelineedit, textedit, spin, doublespin, slider, combothe new valueindex for combo
submitlineeditthe text—
togglecheckbox, radio, checkable button, checkable group'0' / '1'—
selectlist, table, treerow / item idindex
activatelist, table, treerow / item id—
tabtabs, stackthe indexindex
menumenu item—checked
timertimer——
traysystem trayleft / right / double / middle—
press / releasebutton——
commitlineedit (focus lost or Enter)the text—
itemClicklist (every click, even re-clicking the same row)item id—
celltable (cell edited)new textrow, col
expand / collapsetreenode idexpanded
closetabs (close button)the indexindex
loaded / navigatingwebviewthe URLsuccess on loaded
titlewebviewthe document title—

The event object:

['type' => 'click', 'id' => 'btn', 'value' => '…', 'payload' => [...]]

Bridge contract

The 24 functions declared in php-src/qt.stub.php (whose agreement with the C++ implementation qtphp lint verifies):

FunctionDescription
qt_bridge_version(): stringBridge version
qt_app_create(array $options = []): mixedInitialize QApplication (idempotent)
qt_window_create(string $title, array $options = []): mixedCreate a window
qt_window_render(mixed $window, array $tree): voidRender and diff
qt_window_patch(mixed $window, array $ops): voidIncremental patch
qt_window_is_open(mixed $window): boolIs the window open
qt_window_process_events(mixed $window): voidPump one frame of events
qt_window_poll_event(mixed $window): arrayPull one queued event
qt_window_close(mixed $window): voidRequest close
qt_window_destroy(mixed $window): voidDestroy
qt_window_snapshot(mixed $window, string $path): boolSave a PNG
qt_window_widget_value(mixed $window, string $id): mixedRead a widget value
qt_window_set_title(mixed $window, string $title): voidWindow title
qt_window_set_menu(mixed $window, array $items): voidMenu bar
qt_window_set_status(mixed $window, array $segments): voidStatus bar
qt_window_resize(mixed $window, int $width, int $height): voidWindow size
qt_window_message(mixed $window, array $spec): stringMessage box
qt_window_file_dialog(mixed $window, array $spec): arrayFile dialog
qt_window_directory_dialog(mixed $window, array $spec): stringDirectory dialog
qt_window_notify(mixed $window, string $title, string $message): voidSystem notification
qt_window_set_tray(mixed $window, array $spec): voidSystem tray
qt_window_set_timer(mixed $window, string $id, int $intervalMs): voidTimer
qt_clipboard_read(): stringRead the clipboard
qt_clipboard_write(string $text): voidWrite the clipboard

These are internal interfaces

Application code uses QtApp's methods; do not call qt_* directly. This section is for people extending the bridge.


TypePHP\Qt\FakeBridge

A pure-PHP double for the qt_* functions, used by the tests. It defines global functions of the same names and lets you inject events from a script.

It makes domain-layer testing dependency-free — no Qt, no compiler:

qtphp test    # everything goes through FakeBridge

Its limits

FakeBridge runs on a tolerant PHP interpreter, so it structurally cannot reproduce AOT's strictness (a closure arity mismatch, for example). It covers logic, not compilation behaviour — the latter needs --selftest.

Edit this page on GitHub
Last updated: 10/6/26, 3:13 AM
Prev
CLI
Next
Packaging