Running your Qt Design Studio projects with Python

After the adoption of Qt Design Studio, many users started to wonder about the possibilities of running their projects with different types of backends, but until now only C++ was available.

C++ has been the default language to add functionality to Quick-based projects created with QtDS, but with the growing popularity of Python (and PySide), more people were requesting the possibility of easing the process to add a Python backend to the QtDS projects. 

How to get it?

Following the approach with our Python packages, these new components are one command away from your project. Activate the virtual environment where you have your PySide6 installation and use:

pip install PySide6_DS

and that's all! The new components will be added to your PySide6 installation.

Why was this not straightforward? 

QtDS adds a few convenient Quick Components, so people can have more flexibility when importing designs from other applications, like Figma, or Photoshop. These components are not part of a default Qt installation, meaning that the PySide bindings did not include them, generating errors when trying to run projects that included them.

A workaround was to copy those ad-hoc Quick components into the PySide installation environment, but it was a solution that did not scale, due to the volatile nature of Python virtual environments. 

Exporting your project 

With the release of Qt DS 4.6 you can now enable the Python export option, in order to enable your project to work with PySide.

For doing so, you can check on File > Export Project > Enable Python Generator, and you will now have a Python directory within your project files.

 

In the following case, we were using an E-bike example, and when exporting the project you can see the following content. Notice that the Python directory contains a couple of Python files, autogen.py and main.py.

~/QtDesignStudio/examples/EBikeDesign % ls -1  
content/  
Generated/  
imports/  
Python/  
src/  
CMakeLists.txt  
EBikeDesign.qmlproject  
EBikeDesign.qmlproject.qtds  
main.qml  
qmlmodules  
qtquickcontrols2.conf  
~/QtDesignStudio/examples/EBikeDesign % tree Python   
Python  
├── autogen  
│   └── settings.py  
└── main.py  
 
2 directories, 2 files 

The goal of these files, are to provide a main file that contains all the necessary code to launch the application, and a more volatile one for the settings of the project. As you can imagine, while auto-saving your project while editing, only the settings file will be changing in order to provide the url to the main file and the import paths with all the Quick components are located.

What's next?

Considering this is the first release, we are already observing a few things where this can be improved and we are working on a couple of features for the next QtDS release.

Do you have an idea? share it with us!


 


Blog Topics:

Comments