edifice.RadioButton#
- class edifice.RadioButton(checked=False, text='', on_change=None, **kwargs)[source]#
Bases:
QtWidgetElement
[EdRadioButton
]Radio buttons.
Underlying Qt Widget QRadioButton
Radio buttons are used to specify a single choice out of many.
Props
All props from
QtWidgetElement
plus:- Parameters:
checked (
bool
) – Whether or not the RadioButton is checked.text (
str
) – Text for the label of the RadioButton.on_change (
Optional
[Callable
[[bool
],Optional
[Awaitable
[None
]]]]) – Event handler for when the checked value changes, but only when the user checks or unchecks, not when the checked prop changes.
Usage
Because of the declarative nature of Edifice, we can ignore all of the Qt mechanisms for radio button “groups” and “exclusivity.” Just declare each radio button
checked
prop to depend on the state.value, value_set = use_state(cast(Literal["op1", "op2"], "op1")) with ed.VBoxView(): with ed.VBoxView(): ed.RadioButton( checked = value == "op1", on_change = lambda checked: value_set("op1") if checked else None, text = "Option 1", style = {} if value == "op1" else { "color": "grey" }, ) with ed.VBoxView(): ed.RadioButton( checked = value == "op2", on_change = lambda checked: value_set("op2") if checked else None, text = "Option 2", style = {} if value == "op1" else { "color": "grey" }, )
Methods
__init__
([checked, text, on_change])register_ref
(reference)Registers provided
Reference
to this Element.set_key
(key)Set the key of an
Element
.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.