pythonqt icon indicating copy to clipboard operation
pythonqt copied to clipboard

RFC - experience from user migrating from QtScript (Qt5) to pythonqt (Qt6)

Open JulienMaille opened this issue 1 year ago • 3 comments

Hello and thanks a lot for this incredible work. I have a question rather than an issue: I'm desperately looking for a solution to migrate from Qt5 to Qt6 without losing the scriptability of my application. I rely a lot on qtscriptgenerator classes and was using tricks like exposing the a top widget of my app to QtScript and then the "auto-discoverability" of all its widgets (and theit slots/properties), which would allow the scripter to insert his own script-defined widgets, hide or move existing ones, etc. Is this something that I could to with pythonqt? Thanks in advance.

PS: until now I had found https://github.com/qcad/qtjsapi and PySide/Shiboken, how is pythonqt different from the latter (except the setup seems to be much simpler)

JulienMaille avatar Jul 02 '24 12:07 JulienMaille

QJSEngine is still there in qt6 (in Qml qt6 module) if you want to stick to ecma javascript

#include <QJSEngine>
[...]
QJSEngine = my_eng;
my_eng.globalObject().setProperty("myobj", my_eng.newQObject(myobj));
QJSValue retval = my_eng.evaluate("myobj.dosomething()");

iltommi avatar Jul 02 '24 12:07 iltommi

QJSEngine is still there in qt6 (in Qml qt6 module) if you want to stick to ecma javascript

Sure but you can't benefit from QtScriptGenerator, can you?

JulienMaille avatar Jul 02 '24 12:07 JulienMaille

Yes, you can do the things you requested with PythonQt: The Qt API is wrapped for the most part, and you can derive from existing Qt classes in Python.

I don't really know PySide/Shiboken, so I couldn't tell you all the actual differences. One thing that I know of, which makes PythonQt slightly incompatible with PySide, is that Qt proprties take precedence over methods with the same name in PythonQt. Also super() doesn't work for Qt classes in PythonQt, you have to use the class name of the super class.

usiems avatar Jul 03 '24 15:07 usiems