Writing for PyQt5 & PySide2

Heads up! You've already completed this tutorial.

lpozo | 2020-05-07 20:08:51 UTC | #1

https://www.pythonguis.com/blog/pyqt5-vs-pyside2/

Great post Martin! I think you can also use the EAFP approach, and do something like this:

python
try:
# PyQt5
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.QtCore import pyqtSignal as Signal, pyqtSlot as Slot
except ImportError:
# PySide2
from PySide2 import QtGui, QtWidgets, QtCore
from PySide2.QtCore import Signal, Slot

In the qt.py file. What do you think?


martin | 2020-05-07 20:10:53 UTC | #2

Thanks for the comment and good point! This works great for applications where you want to support it running on either binding.

Just a warning though, it might not work so great if you're writing a library where your library is imported by an app using PySide2 but PyQt5 is available in site packages. Bit of an edge case, but exactly the weird things that happen when you write and distribute a library :)


Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt5
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

Writing for PyQt5 & PySide2 was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.