A pythonic layer on top of PyQt6 / PySide6
Project description
hide:
- navigation
PrettyQt: Pythonic layer on top of PyQt6 / PySide6
What is it?
PrettyQt is a Python package that provides a pythonic layer on top of the GUI frameworks PyQt6 / PySide6.
Main Features
- Subclasses for a large part of the Qt classes, enriched with helper and _dunder_ methods to give a feel of a native GUI library.
- more than 80 pre-defined widgets and layouts for common use cases
- more than 30 ItemModels for different data types
- more than 25 general-purpose proxy models
- 10 ItemDelegates for different purposes
- 20 different validators
- Integration with pandas / numpy.
- much, much more.
PrettyQt basically is a wrapper for the whole Qt API (either on top of PySide6 or PyQt6 bindings). Perhaps it can be seen as a small Python equivalent of the KDE framework.
A large part of the library consists of a tree of mixins, with one mixin for each Qt class. These mixins also inherit from each other and are applied to the Qt classes. That way each class gets all helper methods from all sub-mixins.
Example: The class "TreeView" inherits from original Qt Class "QTreeView" and gets helper methods from "TreeViewMxin", "AbstractItemViewMixin", "AbstractScrollAreaMixin", "FrameMixin", "WidgetMixin" and "ObjectMixin".
To illustrate this, we will use some of our included models:
!!! Example "Class hierarchy example"
=== "Subclass tree"
```py
from prettyqt import itemmodels, widgets
app = widgets.app()
widget = widgets.TreeView()
model = itemmodels.SubClassTreeModel(core.AbstractItemModelMixin)
widget.set_model(model)
widget.show()
```
<figure markdown>
![Image title](images/abstractitemmodelmixin_subclasses.png)
<figcaption>AbstractitemModelMixin subclasses</figcaption>
</figure>
=== "Parentclass tree"
```py
from prettyqt import itemmodels, widgets
app = widgets.app()
widget = widgets.TreeView()
model = itemmodels.ParentClassTreeModel(widgets.TreeWidget)
widget.set_model(model)
widget.show()
```
<figure markdown>
![Image title](images/treewidget_parentclasses.png)
<figcaption>TreeWidget parent classes</figcaption>
</figure>
=== "MRO tree"
```py
from prettyqt import itemmodels, widgets
app = widgets.app()
widget = widgets.TreeView()
model = itemmodels.ParentClassTreeModel(widgets.TreeWidget, mro=True)
widget.set_model(model)
widget.show()
```
<figure markdown>
![Image title](images/treewidget_mro.png)
<figcaption>TreeWidget MRO</figcaption>
</figure>
Main objective is to make Qt feel "pythonic". Qt is originally a C++ Framework, and using it can be quite cumbersome for Python developers. (very restrictive when it comes to types, very OOP-centric, lot of enum use, snakeCase naming etc.) PrettyQt aims to improve this by:
- adding more powerful methods to the classes, which accept more types and have more options (in form of keyword arguments)
- doing type conversions for method parameters to lessen the strictness for types.
- raising Exceptions or returning
None
instead of returning-1
or invalid objects. - all enum getters/setters also work with strings. Everything typed with Literals for an excellent IDE experience. (Example: )
- adding a lot of _dunder_ methods to the classes to make them behave like good python citizens.
The minimum supported python version is 3.10. The minimum supported Qt version is 6.5
The aim is to support the last two released Python versions as well as keeping support for the last Qt LTS release.
Covered Qt modules
Qt Module | PrettyQt module |
---|---|
QtBluetooth | prettyqt.bluetooth |
QtCharts | prettyqt.charts |
QtCore | prettyqt.core |
QtDesigner | prettyqt.designer |
QtGui | prettyqt.gui |
QtLocation | prettyqt.location |
QtMultimedia | prettyqt.multimedia |
QtMultimediaWidgets | prettyqt.multimediawidgets |
QtNetwork | prettyqt.network |
QtOpenGLWidgets | prettyqt.openglwidgets |
QtPdf | prettyqt.pdf |
QtPdfWidgets | prettyqt.pdfwidgets |
QtPositioning | prettyqt.positioning |
QtPrintSupport | prettyqt.printsupport |
QtQml | prettyqt.qml |
QtHelp | prettyqt.qthelp |
QtQuick | prettyqt.quick |
QtQuickWidgets | prettyqt.quickwidgets |
QScintilla | prettyqt.scintilla |
QtScXml | prettyqt.scxml |
QtSpatialAudio | prettyqt.spatialaudio |
QtStateMachine | prettyqt.statemachine |
QtSvg | prettyqt.svg |
QtSvgWidgets | prettyqt.svgwidgets |
QtTest | prettyqt.test |
QtTextToSpeech | prettyqt.texttospeech |
QtWebChannel | prettyqt.webchannel |
QtWebEngineCore | prettyqt.webenginecore |
QtWebEngineWidgets | prettyqt.webenginewidgets |
QtWidgets | prettyqt.widgets |
Read more about the general API design.
Apart from the mentioned mixin tree and the corresponding classes, this library also contains a lot of custom widgets, delegates, eventfilters, validators, syntaxhighlighters, layouts, models, proxy models and much more.
Converting to PrettyQt should be very straightforward since the original behaviour of the Qt classes didnt change for the largest parts and all methods from base Qt modules are still available. (There might be a few constructors with slightly different behaviour though.)
Interested? Take a look at the documentation! (even though it totally sucks in its current state.)
Where to get it
The source code is currently hosted on GitHub at: https://github.com/phil65/PrettyQt
The latest released version are available at the Python package index.
# or PyPI
pip install prettyqt
Required dependencies
*Note: Only Qt 6.5+ is supported.
Optional dependencies
Installation from sources
This project uses poetry for dependency management and packaging. Install this first.
In the prettyqt
directory (same one where you found this file after
cloning the git repo), execute:
poetry install
License
Contributing to prettyqt ![Open Source Helpers](https://pypi-camo.freetls.fastly.net/3cee6b1f3c8c6975f097d035bec3d6703c1dba83/68747470733a2f2f7777772e636f64657472696167652e636f6d2f7068696c36352f70726574747971742f6261646765732f75736572732e737667)
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prettyqt-1.53.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 985f094c0e5bc175b9ef824c46f715e0a0608932d614d626db129216a9828210 |
|
MD5 | 75235ec994aec0fdf50cbd9fd015665c |
|
BLAKE2b-256 | c6c3508fb021f4404f3ba6b6bd5bbe39417579eb3b70deed389829a0c704bbd0 |