MeVisLab / pythonqt

Dynamic Python binding for Qt Applications
https://mevislab.github.io/pythonqt/
GNU Lesser General Public License v2.1
234 stars 86 forks source link

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

Open JulienMaille opened 5 days ago

JulienMaille commented 5 days ago

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)

iltommi commented 5 days ago

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()");
JulienMaille commented 5 days ago

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?

usiems commented 4 days ago

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.