Skip to content

Support text elements for PySide widgets that display text - #191

Merged
berendkleinhaneveld merged 1 commit into
masterfrom
pyside-text-elements
Jul 7, 2026
Merged

Support text elements for PySide widgets that display text#191
berendkleinhaneveld merged 1 commit into
masterfrom
pyside-text-elements

Conversation

@berendkleinhaneveld

Copy link
Copy Markdown
Collaborator

Summary

  • implement create_text_element() and set_element_text() in PySideRenderer with a lightweight TextElementProxy that holds text content and a weakref to its parent widget
  • register insert/remove handlers for QLabel and QAbstractButton (covers QPushButton, QRadioButton, QCheckBox, QToolButton) that keep an ordered, anchor-aware list of proxies on the parent and display the joined content through setText()
  • update the counter example to use child text instead of text attributes

This makes templates like the following work:

<widget>
  <label>Count: {{ count }}</label>
  <button @clicked="bump">bump</button>
</widget>

The approach follows #181 (pygfx text elements), but instead of type checks in the renderer's generic insert()/remove() paths, support is opted into per widget type through the existing register_insert/register_remove machinery. This keeps the generic paths free of feature-specific branches, makes it explicit which widgets support child text, and lets custom widgets add support the same way (see pyside/objects/textelement.py). Inserting text into a widget without registered support logs an error, like other unsupported inserts.

Note: since the proxies sync their joined content through setText(), child text overwrites a text="..." attribute set on the same widget — last writer wins.

Fixes #189

Test plan

  • new tests in tests/pyside/test_pyside_text_elements.py: direct renderer tests (label/button text, updates, removal restoring empty text, anchor ordering, unsupported parent) and SFC integration tests (reactive updates via button click, v-if unmount clearing text)
  • full test suite passes (366 passed, 1 skipped)
  • examples/pyside/counter.cgx verified end-to-end offscreen: renders "Count: 0", click updates to "Count: 1"

🤖 Generated with Claude Code

Implement create_text_element() and set_element_text() in the
PySideRenderer with a TextElementProxy object that holds the text
content. Widgets that support text elements as children (QLabel and
QAbstractButton subclasses) register insert/remove handlers that keep
an ordered list of proxies on the parent widget and display the
joined content through setText().

Fixes #189

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@berendkleinhaneveld
berendkleinhaneveld merged commit e501252 into master Jul 7, 2026
9 of 10 checks passed
@berendkleinhaneveld
berendkleinhaneveld deleted the pyside-text-elements branch July 7, 2026 20:37
berendkleinhaneveld added a commit that referenced this pull request Jul 7, 2026
Document the new PySide text element support (#191): update the
renderer-support note in the template syntax guide, add a Text Content
section to the PySide renderer page, and switch the counter examples to
text interpolation to match examples/pyside/counter.cgx.

Document the --show-code CLI flag and the CGX_DEBUG environment
variable (#175) on the CLI page.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
berendkleinhaneveld added a commit that referenced this pull request Jul 7, 2026
* Add MkDocs documentation with GitHub Pages deployment

- Set up MkDocs with Material theme (mkdocs.yml, docs dependency group)
- Add GitHub Actions workflow for building and deploying to GitHub Pages
- Write documentation covering getting started, guide, renderers, reference, and examples
- Add site/ to .gitignore

* Update docs for text interpolation, pygfx text elements, and tree view features

Document features merged from master: text expressions with {{ }} in
element content, pygfx <text> element support (text/markdown attributes,
child text nodes), keyed list reconciliation behavior, and PySide tree
view drag-and-drop with preserved selection/expansion state. Add the new
landmarks, keyed tree, and tree DnD examples to the example pages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Update docs for PySide text elements and --show-code/CGX_DEBUG

Document the new PySide text element support (#191): update the
renderer-support note in the template syntax guide, add a Text Content
section to the PySide renderer page, and switch the counter examples to
text interpolation to match examples/pyside/counter.cgx.

Document the --show-code CLI flag and the CGX_DEBUG environment
variable (#175) on the CLI page.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Update actions in docs workflow to match the other pipelines

Bump checkout to v7, setup-python to v6, and pin setup-uv to the same
sha (v8.3.0) as ci.yml and benchmark.yml. Bump upload-pages-artifact
and deploy-pages to v5.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
berendkleinhaneveld added a commit that referenced this pull request Jul 21, 2026
Features:
- Add pure-Python view API as alternative to cgx templates (#193)
- Support text elements for PySide widgets that display text (#191)

Fixes & internals:
- Fragment parenting overhaul (#162)
- Fix PyInstaller hook for CGX files inside packages (#184)
- Write compiled AST to temp file when CGX_DEBUG is set (#175)

Performance:
- Speed up mount path: cheap arity check, reuse first(), leaner emit (#186)
- Cache Fragment._component_parent() lookups (#187)
- Avoid redundant anchor lookups in Fragment.anchor() and unkeyed v-for (#188)

Documentation:
- Add MkDocs documentation with GitHub Pages deployment (#176)
- Add internals architecture documentation page (#194)
- Add docs badge and links to README (#192)

Tooling & CI:
- Add benchmark suite and per-PR benchmark CI workflow (#185)
- Make benchmark CI guard robust against run-to-run noise (#196)
- Update GitHub actions from Node 20 to Node 24 (#190)
- Migrate from pre-commit to prek (#195)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support text elements for some PySide elements

1 participant