Skip to content

ImageQt does not work as expected in PyQt5 #5266

@driscollis

Description

@driscollis

What did you do?

Attempted to use ImageQt to load a Pillow image in a PyQt5 application

What did you expect to happen?

I expected the image to load correctly. There are no errors, but it does not load the image in PyQt5 correctly.

What actually happened?

The image loaded as a mostly white image with kind of ghost image of the actual photo (see screenshot). I have attached the PyQt5 and PySide6 code, including screenshots from when I ran both files.

Note: The same code works in PySide6, but not in PyQt5.

What are your OS, Python and Pillow versions?

  • OS: MacOS Mojave and Windows 10
  • Python: Python 3.9
  • Pillow: 8.0.0
    pink_flower
import sys

from PIL import Image, ImageQt
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtWidgets import QWidget, QLabel
from PyQt5.QtWidgets import QVBoxLayout, QApplication


class ImageViewer(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.setWindowTitle("PyQt Image Viewer")

        # Open up image in Pillow
        image = Image.open("pink_flower.jpg")
        qt_image = ImageQt.ImageQt(image)
        pixmap = QPixmap.fromImage(qt_image)

        self.image_label = QLabel('')
        self.image_label.setPixmap(pixmap)

        self.main_layout = QVBoxLayout()
        self.main_layout.addWidget(self.image_label)
        self.setLayout(self.main_layout)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    viewer = ImageViewer()
    viewer.show()
    app.exec_()

pyqt_pillow_issue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    QtQt for Python, PyQt, PySide

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions