Type annotations
dawiq.typing provides special type annotations.
- class dawiq.typing.FieldWidgetProtocol(*args, **kwargs)[source]
Bases:
ProtocolType annotation for field widget object.
- fieldValue() Any[source]
Value that the field widget represents.
This is the API for the delegate to get the data from the field widget. For example, in
BoolCheckBoxthis method converts the current check state tobooland returns.If the field value is
None, it typically indicates that the widget is empty and the delegate should specially handle it. One of the few exceptions isBoolCheckBoxwhereNoneindicates partially checked state for fuzzy boolean value.When the field value is changed,
fieldValueChangedsignal must emit the new value. When the field is edited by user,fieldEditedsignal must be emitted with empty argument.
- setFieldValue(value: Any)[source]
Set the value to the field widget.
This method is the API for the delegate to set the data to the widget. For example, in
BoolCheckBoxthis method convertsbooltoQt.CheckStateand sets to the widget.For valid value, its type must be strictly checked and
TypeErrormust be raised on invalid input.
- fieldName() str[source]
Name of the field.
It is recommended to make this name visible in the widget without affecting the data value. Placeholder text of the line edit or title of the group box are good examples.
- setRequired(required: bool)[source]
Set if self represents a required field.
If required is True, it indicates that the field is mandatory. On such case, this methods checks the
fieldValue()of self and setsrequiresFieldValueproperty of the editor widget. If the data value of required field is missing, the property is set to be True.widget.setProperty("requiresFieldValue", True) widget.style().unpolish(widget) widget.style().polish(widget)
The editor widget is usually self, but there are exceptions such as
TupleGroupBox. Note that the widget needs to be re-polished.Style sheet can be set to highlight the required field with empty widget. Common way is to set the style sheet of
QApplicationbefore starting the app.qApp.setStyleSheet( "*[requiresFieldValue=true]{border: 1px solid red}" )
Notes
This method is designed to be called by the
DataclassDelegate, not directly by the user.