edifice.Reference#
- class edifice.Reference[source]#
Bases:
Generic
[_T_Element
]Reference to an
Element
for 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.
Reference
gives us access to a renderedElement
.Create a
Reference
with theuse_ref()
Hook.Element.register_ref()
registers theReference
object to theElement
.Reference
can be dereferenced by calling it. An instance of typeReference[Label]
will dereference to an instance ofLabel
when called.Initially, a
Reference
object will dereference toNone
. After the first render, it will dereference to the renderedElement
. When the renderedElement
dismounts, the reference will once again dereference toNone
.Reference
is valid whenever it is notNone
.Reference
will evaluate false if theElement
isNone
.Access the QWidget underlying a
QtWidgetElement
, through theunderlying
attribute 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__
()