Since the initial port of PySide to Qt5 (a.k.a
PySide2), the interaction with QML was on the list of features we wanted to fully support in our set of bindings, due to the popularity of QML.
With the first official release 5.12, we had cover many use cases for the QML and Python interaction, but also we left out a couple of use cases that were really required by our community. Now that we are developing new features and improvements for Qt6, we wanted to address most of them.
Here you can find a summary of the features that we have done so far for the planned Qt for Python 6.0 release.
The previous limitation of registering a maximum of 50 custom types is gone with 6.0, you may now register as many types as you wish.
Starting with 6.0, you can register custom singletons for use in QML with qmlRegisterSingletonType.
For example if you wanted to expose information about the the operating system to QML, you could create the following class:
osName = Property(str, getOSName)
osRelease = Property(str, getOSRelease)
And then register it under
qmlRegisterSingletonType(SystemInfo, "CustomType", 1, 0, "SystemInfo")
Now you may access
SystemInfo by simply importing
CustomType in your QML code:
import CustomType 1.0
text: "OS Name: " + SystemInfo.osName
Another missing feature was the option to register custom QML types as uncreatable, this will be possible with qmlRegisterUncreatableType
You may use it e.g. to register a custom
enum in QML (which utilizes the new
Default, Dark, HighContrast = range(3)
# ... qmlRegisterUncreatableType(Theme, "CustomType", 1, 0, "Theme", "Theme can't be created")
After registering you can use the
enum like this:
import QtQuick 2.0
import CustomType 1.0
property int theme: Theme.Default
Adapting to the new way of registering types
Qt for Python now also supports a
QmlElement decorator that works in a similar way to
QML_ELEMENT in C++.
QML_IMPORT_NAME = "com.library.name"
QML_IMPORT_MAJOR_VERSION = 1
QML_IMPORT_MINOR_VERSION = 0 # Optional
e.g. this Snippet will expose
ClassForQml to QML and can be imported via the import name and version specified in global variables. This may be especially useful to you if you are registering a lot of types.
We understand that there might be other aspects of the QML + Python interaction that your application currently needs, or will benefit from having it, so we encourage you to share with us missing features, issues, or even new ideas on how we can make Qt for Python a really good alternative for QML-based applications.
Download the latest release here: www.qt.io/download.
Qt 6 was created to be the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu