Repository: python-pillow/Pillow

Issue:
PySide2
The PySide2 (Qt for Python)[1] project developed by qt is now available even in pypi[2], I have always changed ImageQt.py manually, but I think it's time to add such changing to the official source

[1] https://wiki.qt.io/Qt_for_Python
[2] https://pypi.org/project/PySide2


Discussion:
Good to hear, although it looks like it's still at alpha at the moment: 5.11.0a1.dev1530776631953.

https://pypi.org/project/PySide2/#history
The project is yes in alpha, but has been developed since 2015, it is the version of the old pyside (which is not being developed anymore) for Qt 5.

Now that they have managed to increase the file size limit on pypi (something that took a while) else is fully functional.

Even other projects such as QtPy support PySide2 [1] since 2017-08.

[1] https://github.com/spyder-ide/qtpy/blob/master/CHANGELOG.md

I think that this has since jumped out of alpha. The latest version at https://pypi.org/project/PySide2/#history is 5.11.1

Resolving patch:
diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py
--- a/src/PIL/ImageQt.py
+++ b/src/PIL/ImageQt.py
@@ -23,6 +23,7 @@
 
 qt_versions = [
     ['5', 'PyQt5'],
+    ['side2', 'PySide2'],
     ['4', 'PyQt4'],
     ['side', 'PySide']
 ]
@@ -33,6 +34,9 @@
         if qt_module == 'PyQt5':
             from PyQt5.QtGui import QImage, qRgba, QPixmap
             from PyQt5.QtCore import QBuffer, QIODevice
+        elif qt_module == 'PySide2':
+            from PySide2.QtGui import QImage, qRgba, QPixmap
+            from PySide2.QtCore import QBuffer, QIODevice
         elif qt_module == 'PyQt4':
             from PyQt4.QtGui import QImage, qRgba, QPixmap
             from PyQt4.QtCore import QBuffer, QIODevice


Test patch:
diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py
--- a/Tests/test_imageqt.py
+++ b/Tests/test_imageqt.py
@@ -33,6 +33,8 @@ def setUp(self):
                 from PyQt4.QtGui import QGuiApplication
             elif ImageQt.qt_version == 'side':
                 from PySide.QtGui import QGuiApplication
+            elif ImageQt.qt_version == 'side2':
+                from PySide2.QtGui import QGuiApplication
         except ImportError:
             self.skipTest('QGuiApplication not installed')
 
@@ -56,6 +58,8 @@ def test_rgb(self):
             from PyQt4.QtGui import qRgb
         elif ImageQt.qt_version == 'side':
             from PySide.QtGui import qRgb
+        elif ImageQt.qt_version == 'side2':
+            from PySide2.QtGui import qRgb
 
         self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255))
 
diff --git a/Tests/test_qt_image_toqimage.py b/Tests/test_qt_image_toqimage.py
--- a/Tests/test_qt_image_toqimage.py
+++ b/Tests/test_qt_image_toqimage.py
@@ -13,13 +13,21 @@
         QT_VERSION = 5
     except (ImportError, RuntimeError):
         try:
-            from PyQt4 import QtGui
-            from PyQt4.QtGui import QWidget, QHBoxLayout, QLabel, QApplication
-            QT_VERSION = 4
+            from PySide2 import QtGui
+            from PySide2.QtWidgets import QWidget, QHBoxLayout, QLabel, \
+                QApplication
+            QT_VERSION = 5
         except (ImportError, RuntimeError):
-            from PySide import QtGui
-            from PySide.QtGui import QWidget, QHBoxLayout, QLabel, QApplication
-            QT_VERSION = 4
+            try:
+                from PyQt4 import QtGui
+                from PyQt4.QtGui import QWidget, QHBoxLayout, QLabel, \
+                    QApplication
+                QT_VERSION = 4
+            except (ImportError, RuntimeError):
+                from PySide import QtGui
+                from PySide.QtGui import QWidget, QHBoxLayout, QLabel, \
+                    QApplication
+                QT_VERSION = 4
 
 
 class TestToQImage(PillowQtTestCase, PillowTestCase):