edifice.CustomWidget#
- class edifice.CustomWidget(*args, **kwargs)[source]#
Bases:
QtWidgetElement
[_T_customwidget
]Custom widgets that you can define.
Not all widgets are currently supported by Edifice. You can create your own base Qt Widget element by inheriting from
QtWidgetElement
directly, or more simply by overridingCustomWidget
:class MyWidgetElement(CustomWidget[QtWidgets.FooWidget]): def __init__(self, text="", value=0, **kwargs): super().__init__(**kwargs) self._register_props( { "text": text, "value": value, } ) def create_widget(self): # This function should return the new widget # (with parent set to None; Edifice will handle parenting) return QtWidgets.FooWidget() def update(self, widget: QtWidgets.FooWidget, diff_props: PropsDiff): # This function should update the widget match diff_props.get("text"): case _propold, propnew: widget.setText(propnew) match diff_props.get("value"): case _propold, propnew: widget.setValue(propnew)
The two methods to override are
CustomWidget.create_widget()
, which should return the Qt widget, andCustomWidget.update()
, which takes the current widget and props diff, and should update the widget according to the new props. The custom widget inherits fromQtWidgetElement
, allowing the user to, for example, set the style.Methods
__init__
(*args, **kwargs)Create the widget on first render.
register_ref
(reference)Registers provided
Reference
to this Element.set_key
(key)Set the key of an
Element
.update
(widget, diff_props)Update the widget based on the diff_props.
Attributes
children
The children of this Element.
props
The props of this Element.
underlying
The underlying QWidget, which may not exist if this Element has not rendered.