Different import name (PySide instead of PyQt4)

PySide only supports PyQt’s “API 2” (PSEP 101)

PyQt provides two different APIs[riverbankcomputing.co.uk], the first of which provides QStrings, QVariants, etc as is in Python. The new API 2 provides automatic conversion between the Qt classes and respective native Python datatypes and is much more Pythonic in nature. PyQt on Python 2.x defaults to API 1, while PyQt on Python 3 defaults to API 2.

PySide only supports PyQt’s API 2 (see PSEP 101[pyside.org]) for details. Therefore Qt classes such as QStrings, QStringLists, and QVariants are not available on PySide. Instead, you should simply use native Python datatypes.

If you’re porting code from PyQt, you might want to first modify the PyQt code to use API 2 (using a sip.setapi(class,ver) call before importing PyQt4), and only after getting that change working, change the imports to use PySide instead.

NB: Due to the API change, QFileDialog.getOpenFileName returns a tuple in PySide, which often is an issue when porting code from PyQt. See e.g. bug 343[bugs.openbossa.org].

For example, this affects functions such as QColor.dark() and QColor.light(), instead of which QColor.darker() and QColor.lighter() need to be used.

sender() method returns None when used within a partial or a lambda

If a lambda is used as a slot, sender() cannot be used to acquire the object that emitted the signal. This works in PyQt, but their implementation behaves incorrectly in certain situations. See bug 344[bugs.openbossa.org] for details.

When inheriting classes, parent class constructors need to be always called

Only signals without arguments can be auto connected on constructor.

The triggered() signal will be connected to the slot handler instead of the triggered(bool) signal.

Supporting Both APIs

qt_compat.py[github.com] is an example of centralizing the knowledge of PySide and PyQt without using monkey-patching. It serves both to point out what differences exist as well as keeping your code binding-agnostic. This is important for when needing to support both bindings, usually when transitioning from one to the other and needing to continue to support older distributions that do not yet come with PySide.

python_qt_binding[github.com] is a Python package from the ROS[ros.org] middleware which gives a more extensive example of how to keep your code agnostic of the actual Python-Qt binding used. It offers a very transparent abstraction, allowing you to write standard import lines like