Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyQt6 Support #5256

Closed
Aulla opened this issue Feb 9, 2021 · 7 comments · Fixed by #5258
Closed

PyQt6 Support #5256

Aulla opened this issue Feb 9, 2021 · 7 comments · Fixed by #5258
Labels
Qt Qt for Python, PyQt, PySide

Comments

@Aulla
Copy link

Aulla commented Feb 9, 2021

Hi everyone!. I'm updating my app to PyQt6 and found a problem.

ImageQt.ImageQt class raises an error when try to use with QPainter:

>>> page_image = ImageQt.ImageQt(page)
>>> painter = QtGui.QPainter()
>>> painter.begin(page_image)
TypeError: begin(self, QPaintDevice): argument 1 has unexpected type 'ImageQt'

Regards

Python 3.8.6
Ubuntu 20.04
PyQt6 6.0.1
Pillow 8.1.0

@radarhere radarhere added the Qt Qt for Python, PyQt, PySide label Feb 9, 2021
@radarhere
Copy link
Member

Hi. ImageQt subclasses QImage, and QImage subclasses QPaintDevice, so I don't see an obvious reason why this shouldn't work.

Are you saying that this code worked with PyQt5?

@Aulla
Copy link
Author

Aulla commented Feb 9, 2021

Hello, Yes, works fine with PyQt5. the problem is that inside ImageQt.py there is a list to know which package contains the class to search for.

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

As PyQt6 is not defined, it cannot know which package provides each Class a little lower.

# 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 == "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":
            from PySide2.QtCore import QBuffer, QIODevice
            from PySide2.QtGui import QImage, QPixmap, qRgba
    except (ImportError, RuntimeError):
        continue
    qt_is_installed = True
    break
else:
    qt_is_installed = False
    qt_version = None

Another problem that exists is the regrouping of the Enums, for example:
QImage.Format_RGB32
change to :
QImage.Format.Format_RGB32

Regards.

@radarhere
Copy link
Member

Ah, I misunderstood. I thought you meant something specific to the code you mentioned.

I've created #5258 to add support. If you could test it and let us know if it works for you, that could be helpful.

@Aulla
Copy link
Author

Aulla commented Feb 10, 2021

with the changes ... begin(self, QPaintDevice): argument 1 has unexpected type 'ImageQt'.

Original QImage is need for class ImageQt parent, not OpenMode. import OpenMode as QIODevice also gives problems.

@radarhere
Copy link
Member

Ok, thanks for checking. I've updated the PR if you wanted to try again.

@Aulla
Copy link
Author

Aulla commented Feb 10, 2021

the new changes works Ok! . Thanks!!

@hugovk
Copy link
Member

hugovk commented Feb 10, 2021

Thanks both! Merging, it'll be in the next release at the start of April.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Qt Qt for Python, PyQt, PySide
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants