The ImageQt Module
The ImageQt module provides compatibility layers to convert standard PIL image instances directly into PyQt toolkit QImage objects. This linkage lets developers apply rapid pixel modifications or file I/O operations through PIL while leveraging the native performance of Qt applications to render those graphics on desktop interfaces.
Practical PyQt Integration Example
The implementation below demonstrates how to initialize an ImageQt container block and pass it straight down into a standard desktop GUI widget element context:
from PIL import Image, ImageQt
from PyQt4 import QtGui, QtCore
import sys
# Instantiate a default application frame window environment
app = QtGui.QApplication(sys.argv)
# Open an active raster bitmap asset via PIL channels
with Image.open("display_layer.png") as pil_img:
# Convert the pixel matrix into a shared Qt buffer interface
qt_image_buffer = ImageQt.ImageQt(pil_img)
# Generate a native paintable graphic scene asset (QPixmap)
pixmap_surface = QtGui.QPixmap.fromImage(qt_image_buffer)
# Mount the visual container layout element within a standard label widget
ui_display_frame = QtGui.QLabel()
ui_display_frame.setPixmap(pixmap_surface)
ui_display_frame.show()
sys.exit(app.exec_())
Classes Reference
Constructs an ImageQt translation wrapper instance around a predefined, live PIL image reference object.
Because this utility implementation operates explicitly as a subclass of QtGui.QImage, the generated wrapper instances are compatible with all PyQt API methods, function parameters, and frame widgets without needing additional type-casting operations or layout overhead.
Supported Image Formats & Modes
The internal image transformation mapping matrix runs exclusively on pixel arrays utilizing the following standard canonical configurations:
"I" variables or floating-point scientific "F" streams) into the constructor will trigger layout conversion errors. Run explicit image normalization workflows on unlisted structures beforehand:
# Flatten unsupported CMYK or high-depth variants prior to binding
sanitized_img = target_img.convert("RGBA")
qt_view = ImageQt.ImageQt(sanitized_img)