Testing, I found I was able to use GitHub Actions to reproduce the matter.
Testing further, I found that it was only happening when qimage was inside the function - if I unwrapped the function so that qimage wouldn'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 was
This is caused by Qt's implicit data sharing. The QImage will be garbage-collected when wrap returns, which may mean some of the shared data is no longer accesible. To avoid these problems, call pixmap.detach() to enforce a copy-on-write.
This fix allows us to test PyQt6 in GitHub Actions with CPython, which would otherwisefail.
Alternative to #8507
The user in that PR reported seeing corrupt output from
ImageQt.toqpixmap()
on Windows.https://github.com/python-pillow/Pillow/blob/9a4b3e05d643c92f050df5713e48225a9f36497e/src/PIL/ImageQt.py#L214-L216
Testing, I found I was able to use GitHub Actions to reproduce the matter.
Testing further, I found that it was only happening when
qimage
was inside the function - if I unwrapped the function so thatqimage
wouldn'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.