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

toqpixmap() doesn't work with PyQt5 #7994

Closed
niklashenning opened this issue Apr 19, 2024 · 6 comments
Closed

toqpixmap() doesn't work with PyQt5 #7994

niklashenning opened this issue Apr 19, 2024 · 6 comments

Comments

@niklashenning
Copy link

niklashenning commented Apr 19, 2024

What did you do?

I tried using .toqpixmap() on a Pillow Image to convert it to a QPixmap in a PyQt5 application

What did you expect to happen?

I expected the image to load and show but the program just crashes.

What actually happened?

The program instantly crashes without the debugger even showing anything: Process finished with exit code -1073740791 (0xC0000409)

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: Python 3.11.3
  • Pillow: 10.1.0

features.pilinfo(supported_formats=False):

--------------------------------------------------------------------
Pillow 10.1.0
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]
--------------------------------------------------------------------
Python modules loaded from C:\Users\NH\AppData\Local\Programs\Python\Python311\Lib\site-packages\PIL
Binary modules loaded from C:\Users\NH\AppData\Local\Programs\Python\Python311\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.15
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.0
--- ZLIB (PNG/ZIP) support ok, loaded 1.3
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

Not working with PyQt5:

import sys
from PIL import Image
from PyQt5.QtWidgets import QMainWindow, QLabel, QApplication


# NOT WORKING
class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)

        image = Image.open('test.png')

        self.label = QLabel(self)
        self.label.setPixmap(image.toqpixmap())
        self.label.setFixedSize(64, 64)
        self.label.move(0, 0)


app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

Same code with PyQt6 works:

import sys
from PIL import Image
from PyQt6.QtWidgets import QMainWindow, QLabel, QApplication


# WORKING
class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)

        image = Image.open('test.png')

        self.label = QLabel(self)
        self.label.setPixmap(image.toqpixmap())
        self.label.setFixedSize(64, 64)
        self.label.move(0, 0)


app = QApplication(sys.argv)
window = Window()
window.show()
app.exec()

I found this workaround to be working for PyQt5, but honestly I'd rather figure out why toqpixmap() isn't working:

import sys
from PIL import Image
from PyQt5 import QtGui
from PyQt5.QtGui import QImage, QPixmap
from PyQt5.QtWidgets import QMainWindow, QLabel, QApplication


# WORKAROUND
class Window(QMainWindow):
    def __init__(self):
        super().__init__(parent=None)

        image = Image.open('test.png')
        q_image = QImage(image.tobytes('raw', 'RGBA'), image.width,
                         image.height, QtGui.QImage.Format.Format_RGBA8888)

        self.label = QLabel(self)
        self.label.setPixmap(QPixmap.fromImage(q_image))
        self.label.setFixedSize(64, 64)
        self.label.move(0, 0)


app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
@niklashenning
Copy link
Author

I uploaded the examples and the image:
issue_7994_code.zip

@Yay295
Copy link
Contributor

Yay295 commented Apr 19, 2024

What does this say?

from PIL import ImageQt
print(ImageQt.qt_is_installed)

@niklashenning
Copy link
Author

What does this say?

from PIL import ImageQt
print(ImageQt.qt_is_installed)

This prints True

@Yay295
Copy link
Contributor

Yay295 commented Apr 19, 2024

Ah, #7059 would be the reason.

@niklashenning
Copy link
Author

Oh, I didn't expect that. Thanks for the quick help!

@radarhere radarhere closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
@radarhere
Copy link
Member

Just to explicitly state here - Qt5 support was removed in Pillow 10.0.0. See https://pillow.readthedocs.io/en/stable/deprecations.html#pyqt5-and-pyside2

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

No branches or pull requests

3 participants