Detach PyQt6 QPixmap instance before returning#8509
Detach PyQt6 QPixmap instance before returning#8509hugovk merged 1 commit intopython-pillow:mainfrom
Conversation
|
This resolved the issue #8507. RGB and RGBA work correctly. |
| qimage = toqimage(im) | ||
| return getattr(QPixmap, "fromImage")(qimage) | ||
| pixmap = getattr(QPixmap, "fromImage")(qimage) | ||
| if qt_version == "6": |
There was a problem hiding this comment.
This "6" means PyQt, and "side6" would mean PySide6.
Do we know if this also affects PySide6?
There was a problem hiding this comment.
I'm unable to replicate the problem on Windows on GitHub Actions with PySide6.
If I run the test suite with PySide6 without this fix, it passes.
Furthermore, detach() doesn't exist in PySide6 - https://doc.qt.io/qtforpython-6/PySide6/QtGui/QPixmap.html / https://github.com/python-pillow/Pillow/actions/runs/11554805812/job/32158808074#step:6:5698. It is possible they don't offer it precisely because it isn't needed?
There was a problem hiding this comment.
Thanks for testing, let's merge. We'll have to see what happens when/if PyQt7 comes out in the future.
Alternative to #8507
The user in that PR reported seeing corrupt output from
ImageQt.toqpixmap()on Windows.Pillow/src/PIL/ImageQt.py
Lines 214 to 216 in 9a4b3e0
Testing, I found I was able to use GitHub Actions to reproduce the matter.
Testing further, I found that it was only happening when
qimagewas inside the function - if I unwrapped the function so thatqimagewouldn't be garbage collected, the problem disappeared. I created a reproduction just using PyQt6 and asked about this at https://stackoverflow.com/questions/79133259/corrupted-display-from-qpixmap-fromimage. The response I received wasThis fix allows us to test PyQt6 in GitHub Actions with CPython, which would otherwise fail.