edifice.Reference#
- class edifice.Reference[source]#
Bases:
Generic[_T_Element]Reference to an
Elementfor imperative commands.Edifice tries to abstract away the need to issue imperative commands to widgets but this is not always possible and not every feature of Qt Widgets is supported by Edifice. In some cases, we might need to issue imperative commands to the Elements and their underlying Qt Widgets.
Referencegives us access to a renderedElement.Create a
Referencewith theuse_ref()Hook.Element.register_ref()registers theReferenceobject to theElement.Referencecan be dereferenced by calling it. An instance of typeReference[Label]will dereference to an instance ofLabelwhen called.Initially, a
Referenceobject will dereference toNone. After the first render, it will dereference to the renderedElement. When the renderedElementdismounts, the reference will once again dereference toNone.Referenceis valid whenever it is notNone.Referencewill evaluate false if theElementisNone.Access the QWidget underlying a
QtWidgetElement, through theunderlyingattribute of theQtWidgetElement.use_effect()Hooks always run after the Elements are fully rendered.@component def MyComp(self): label_ref:Reference[Label] = use_ref() def did_render(): label = label_ref() if label and label.underlying: # Set the text of the Label’s underlying QLabel widget. label.underlying.setText("After") use_effect(did_render, ()) with VBoxView(): Label("Before").register_ref(label_ref)
Methods
__init__()