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

    • Guide
    • Installation
    • Installing and Building Qt
    • Quick Start
    • Project Structure
    • Architecture
    • State and View
  • The UI

    • Events and Handlers
    • Properties
    • Layout
    • Dialogs and System Integration
    • Multiple Windows, Tray and Timers
    • Patching

Properties

Properties are an associative array on a widget-tree node, passed as the third or second argument.

WidgetTree::label('Hello', ['id' => 'greeting', 'style' => 'color:red', 'align' => 'center']);

Common to every node

PropertyTypeMeaning
idstringThe stable identity — the diff and the events both key on it. Any control you read or write needs one
visibleboolShow / hide
enabledboolInteractive or not
tooltipstringHover text
stylestringA Qt stylesheet fragment, e.g. color:#1d4ed8;font-weight:bold;
size[w, h]Fixed size
min_size / max_size[w, h]Size constraints
alignstringleft right center
growintStretch weight within its layout (0 = no stretch)

Container properties

PropertyApplies toMeaning
titlegroup, tabs, tabTitle text
marginlayout containersOuter margin: an int, or [top, right, bottom, left]
spacinglayout containersGap between children
row / colgrid, formGrid position
row_span / col_spangridSpan across rows / columns
orientationsplith / v
sizessplitInitial split ratio, e.g. [200, 400]
tab_positiontabstop bottom left right

Input properties

PropertyApplies toMeaning
texttext controlsThe text content
placeholderlineedit, texteditPlaceholder hint
readonlylineedit, texteditRead-only
passwordlineeditPassword mode (dots)
clear_buttonlineeditShow a clear button
max_lengthlineeditMaximum characters
wraptexteditWord wrap

Numeric properties

PropertyApplies toMeaning
valueall numeric controlsCurrent value
min / maxall numeric controlsRange
stepspin, doublespin, sliderStep
decimalsdoublespinDecimal places
prefix / suffixspin, doublespinAffixes, e.g. $ / %
tickssliderTick marks

List properties

PropertyApplies toMeaning
itemscombo, listItem text list
currentcombo, list, table, tree, tabs, stackDeclarative selection — the meaning varies, see below
columnstableHeader text list
rowstableRow data (each row is a list of cells)
row_idstableRow id list
row_colorstablePer-row background color ('' = default, no fill); e.g. ['#f8d7da', '', '#d4edda']
nodestreeTree nodes
headerstreeColumn headers
headers_visibletable, treeShow the header row
multilist, table, treeAllow multi-select
select_modetable, treeSelection mode
stretch_lasttableLet the last column stretch
row_heighttableFixed row height in px. 0 (default) = height follows the content; a table whose cells contain \n is resized automatically so multi-line cells are not clipped
checkablelist, table, treeItems carry checkboxes
editablecombo, tableEditable (on a table this enables in-place cell editing and the cell event)

current means different things per control

This is the easiest thing to get wrong — the same current property takes a different type on different controls:

ControlWhat current takes
tablea row id (without row_ids, the row id is the index string '0', '1', …)
treea node id (without one, it falls back to the node's text)
lista row index
combo / tabs / stackan index or the text
// table: select by row id
WidgetTree::table(['Name', 'Qty'], $rows, ['id' => 'tbl', 'row_ids' => ['r1', 'r2'], 'current' => 'r2']);

// combo: select by text
WidgetTree::combo(['Light', 'Dark'], 'Dark', ['id' => 'theme']);

// list: select by index
WidgetTree::list(['A', 'B', 'C'], 1, ['id' => 'lst']);

Selection is recovered when current is omitted

On re-render the framework recovers the previous selection by row id / node id, so inserting a row or swapping the data never misplaces the selection. This is part of the diff engine — see Diff Engine.

Display properties

PropertyApplies toMeaning
hreflinkLink target (reported as value on click)
pathimageImage path
scaled_sizeimageScale size
boldlabelBold
font_sizelabel, buttonFont size
checkablebuttonToggle button
flatbuttonBorderless
checkedbutton, checkbox, radioChecked state
defaultbuttonDefault button (triggered by Enter)

Unknown properties are ignored

Writing a property that does not exist is not an error — it simply has no effect, consistent with unknown ids and unknown patch methods. That makes graceful degradation and typo tolerance easy, but a typo will not tell you — so check against this table.

Styling with style

style is a Qt stylesheet (QSS) fragment, written on the node:

WidgetTree::label('Title', [
    'id' => 'title',
    'style' => 'font-size:22px;font-weight:bold;color:#1d4ed8;',
])

You can also set one globally, at create() time:

$app->create(['name' => 'MyApp', 'stylesheet' => 'QPushButton { padding: 6px 14px; }']);

Size and layout

  • size is a fixed size and overrides the layout's automatic computation.
  • grow is a stretch weight — when the layout has spare space it is distributed by weight. An item with grow => 1 takes all of it.
  • min_size / max_size are constraints, best used together with grow.
WidgetTree::hbox([
    WidgetTree::label('Sidebar', ['size' => [180, 0]]),         // fixed width 180
    WidgetTree::textEdit('', ['id' => 'main', 'grow' => 1]),    // takes the rest
]);
Edit this page on GitHub
Last updated: 10/6/26, 3:13 AM
Prev
Events and Handlers
Next
Layout