QT vs pyside versions

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
efferre
Posts: 41
Joined: Tue Jul 03, 2018 12:41 pm

QT vs pyside versions

Post by efferre »

Freecad can be compiled against Qt4 or Qt5, the two frameworks are supported by pyside and pyside2 respectively. Freecad compiled with BUILD_QT5 seems to work without problems with python scripts using pyside (and not pyside2). It seems someone is doing some magic behind the scenes, here is what I see in the python console:

Code: Select all

>>> import PySide
>>> PySide.__version_info__
(5, 9, 0, 'a', 1)
>>> import PySide2
>>> PySide2.__version_info__
(5, 9, 0, 'a', 1)
So effectively the two modules look the same. Furthermore:

Code: Select all

>>> from PySide import QtGui
>>> QtGui.QMessageBox()
<PySide2.QtWidgets.QMessageBox object at 0x7f66fd7c8200>
>>> from PySide2 import QtGui
>>> QtGui.QMessageBox()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'module' object has no attribute 'QMessageBox'
It seems that when using PySide there is a compatibility layer that converts automatically to qt5 code.

Can someone explain what happens and how this works? Is it better to code python scripts with pyside or pyside2?
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: QT vs pyside versions

Post by looo »

We use an layer on top of PySide2 to make python stuff done with PySide compatible with PySide2.
Here the magic parts are introduced: https://github.com/FreeCAD/FreeCAD/blob ... #L991L1001

I think we officially support the old PySide-API and if you want to make addons compatible with PySide and PySide2 it's best to use the old API.
efferre
Posts: 41
Joined: Tue Jul 03, 2018 12:41 pm

Re: QT vs pyside versions

Post by efferre »

Thank you for the clarification, now it is clear. PySide installed on the system is masked by the wrapper shipped with FreeCAD:

Code: Select all

>>> import PySide
>>> PySide.__path__
['/usr/share/freecad-0.17/Ext/PySide']
>>> import PySide2
>>> PySide2.__path__
['/usr/lib64/python3.5/site-packages/PySide2']
Post Reply