Skip to content

Commit

Permalink
Merge pull request #5161 from hugovk/add-pyside6
Browse files Browse the repository at this point in the history
Add support for PySide6
  • Loading branch information
radarhere authored Jan 1, 2021
2 parents 11e63b6 + effa65c commit f54ea8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Tests/test_imageqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def test_rgb():
# typedef QRgb
# An ARGB quadruplet on the format #AARRGGBB,
# equivalent to an unsigned int.
if ImageQt.qt_version == "5":
if ImageQt.qt_version == "side6":
from PySide6.QtGui import qRgb
elif ImageQt.qt_version == "5":
from PyQt5.QtGui import qRgb
elif ImageQt.qt_version == "side2":
from PySide2.QtGui import qRgb
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_qt_image_qapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
if ImageQt.qt_is_installed:
from PIL.ImageQt import QPixmap

if ImageQt.qt_version == "5":
from PyQt5 import QtGui
if ImageQt.qt_version == "side6":
from PySide6.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
elif ImageQt.qt_version == "5":
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
elif ImageQt.qt_version == "side2":
from PySide2 import QtGui
from PySide2.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget

class Example(QWidget):
Expand All @@ -22,7 +22,7 @@ def __init__(self):

qimage = ImageQt.ImageQt(img)

pixmap1 = QtGui.QPixmap.fromImage(qimage)
pixmap1 = ImageQt.QPixmap.fromImage(qimage)

QHBoxLayout(self) # hbox

Expand Down
11 changes: 9 additions & 2 deletions src/PIL/ImageQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@
from . import Image
from ._util import isPath

qt_versions = [["5", "PyQt5"], ["side2", "PySide2"]]
qt_versions = [
["side6", "PySide6"],
["5", "PyQt5"],
["side2", "PySide2"],
]

# If a version has already been imported, attempt it first
qt_versions.sort(key=lambda qt_version: qt_version[1] in sys.modules, reverse=True)
for qt_version, qt_module in qt_versions:
try:
if qt_module == "PyQt5":
if qt_module == "PySide6":
from PySide6.QtCore import QBuffer, QIODevice
from PySide6.QtGui import QImage, QPixmap, qRgba
elif qt_module == "PyQt5":
from PyQt5.QtCore import QBuffer, QIODevice
from PyQt5.QtGui import QImage, QPixmap, qRgba
elif qt_module == "PySide2":
Expand Down

0 comments on commit f54ea8f

Please sign in to comment.