Introduction

DaWiQ is a Python package for generating Qt widget from the dataclass.

Here is a PySide6 example for widget construction.

from dataclasses import dataclass
from dawiq import dataclass2Widget
from PySide6.QtWidgets import QApplication
import sys

@dataclass
class DataClass:
    x: int
    y: bool

app = QApplication(sys.argv)
dataWidget = dataclass2Widget(DataClass)
dataWidget.show()
app.exec()
app.quit()
_images/widget-example.jpg

Appearance of dataWidget

For other Qt bindings, see the examples in User guide.

Supported field types

DaWiQ constructs the widget for each field by using its type hint. By default, the following types are supported:

How about other types?

Any other type can be supported by defining special metadata to the dataclass field:

  • Qt_typehint: type hint for widget construction

  • toQt_converter: converts dataclass data to widget data

  • fromQt_converter: converts widget data to dataclass data

For more information, see How to create dataclass widget and How to use item model.

Supported Qt bindings

DaWiQ is compatible with the following Qt binding packages:

When DaWiQ is imported, available package is searched and selected in the order mentioned above. To force a particular API, set environment variable DAWIQ_QT_API with package name. Letter case does not matter.