Skip to content

Commit

Permalink
Fix for PyQt6
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 16, 2021
1 parent 2f29c12 commit d114837
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/PIL/ImageQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
for qt_version, qt_module in qt_versions:
try:
if qt_module == "PyQt6":
from PyQt6.QtCore import QBuffer, QIODevice
from PyQt6.QtCore import QBuffer, QIODevice, QIODeviceBase
from PyQt6.QtGui import QImage, QPixmap, qRgba
elif qt_module == "PySide6":
from PySide6.QtCore import QBuffer, QIODevice
Expand Down Expand Up @@ -66,7 +66,13 @@ def fromqimage(im):
:param im: QImage or PIL ImageQt object
"""
buffer = QBuffer()
qt_openmode = QIODevice.OpenMode if qt_version == "6" else QIODevice
if qt_version == "6":
try:
qt_openmode = QIODeviceBase.OpenModeFlag
except AttributeError:
qt_openmode = QIODevice.OpenMode
else:
qt_openmode = QIODevice
buffer.open(qt_openmode.ReadWrite)
# preserve alpha channel with png
# otherwise ppm is more friendly with Image.open
Expand Down

0 comments on commit d114837

Please sign in to comment.