Skip to content

Build Qt applications in a reactive, declarative, and composable way.

License

Notifications You must be signed in to change notification settings

Lucino772/qtcompose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qtcompose

Build Qt applications in a reactive, declarative, and composable way.

qtcompose lets you describe your UI as a tree of components whose properties are driven by reactive values. Update state and the UI updates automatically.

Warning

This project is under active development. APIs and behavior may change quickly, and documentation is still in progress. Feedback and early experimentation are welcome.

Installation

pip install qtcompose

You’ll also need a Qt binding. The examples use PySide6.

pip install PySide6

Quick example

A small counter app where the label updates automatically when count changes:

from PySide6 import QtWidgets
from qtcompose.rx import Subject, fn
from qtcompose.ui import (
    QBoxLayoutItem,
    QLabel,
    QMainWindow,
    QPushButton,
    QVBoxLayout,
    QWidget,
)

app = QtWidgets.QApplication()

count = Subject(0)

window = QMainWindow(
    children=Subject(
        QWidget(
            layout=Subject(
                QVBoxLayout(
                    children=Subject(
                        [
                            QBoxLayoutItem.Child(
                                QLabel(
                                    text=fn.pipe(
                                        count,
                                        fn.map_(lambda cnt: f"Count: {cnt}")
                                    )
                                )
                            ),
                            QBoxLayoutItem.Child(
                                QPushButton(
                                    text=Subject("Click Me!"),
                                    on_click=Subject(
                                        lambda _: count.push(
                                            lambda prev: prev + 1
                                        )
                                    ),
                                )
                            ),
                        ]
                    )
                )
            )
        )
    )
)()

window.show()
app.exec()

Further reading

For a deeper explanation of the ideas behind this project, check out my blog post:

About

Build Qt applications in a reactive, declarative, and composable way.

Resources

License

Stars

Watchers

Forks

Packages

No packages published