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

Commenting for this post has ended.

Stefan Kebekus
2 points
40 months ago

Same question here … I am waiting for QML Maps before I can port my mobile app from Qt5 to Qt6…

Celandre Dzimiwine
1 point
40 months ago

Thanks guys, especially for QML Treeview. However, QtCreator fails to recognize Qt 6.3 saying that the Qt version is not properly installed. I am also getting error related to missing /permissive- MVSC (2019) options. I failed to fix this issue even when adding /permissive- option in my CMakefiles.

K
Kimmo Leppälä
0 points
40 months ago

Unfortunately, there was a packaging issue which is triggering this failure to detect Qt version in Qt Creator. Root cause is tracked here: https://bugreports.qt.io/browse/QTBUG-99656. The fix for this is already available and will be released in Qt 6.3 beta1 by latest.

Kai Köhne
0 points
39 months ago

What compiler error do you get, related to /permissive? Could you maybe file a bug with the complete error message at bugreports.qt.io?

Г
Государство 2.0 - Принципы успеха
0 points
40 months ago

Hi, will qml Map be included in 6.3 release?

Philip Schuchardt
0 points
40 months ago

Wow, QML TreeView is finally been added!

H
HM
0 points
40 months ago

Include Qt Speech with 6.4 release please :). Then we can finally upgrade to Qt 6.

Dmitry Logov
0 points
40 months ago

Qt 6.3 alpha windows release is broken, it shows "Invalid Qt version" in the configuration page.

Jani Heikkinen
0 points
39 months ago

Hi! Unfortunately some users are seeing this error with Qt 6.3.0 Alpha, see https://bugreports.qt.io/browse/QTCREATORBUG-26876. The issue should be fixed properly in Qt 6.3.0 Beta1 release which is targeted to be released still during January. Meanwhile you can try a dirty workaround: remove qt.conf file from installations /bin directory. After that Qt Creator seems to work OK with Qt 6.3.0 Alpha

Y
yyyu
0 points
39 months ago

Will qt enter the server field, I am looking forward to Qt Httpserver

M
Maurice Kalinowski
0 points
39 months ago

We are currently looking into feasible options and timing for a finalized Qt Http Server.

A
aaa
0 points
38 months ago

Have no idea how to build 6.3 with wasm... There are just errors. Is there an algorithm?