Skip to content

Commit dd05bd0

Browse files
Fix image memory issues (maintenance branch) (#1111)
* Fix QPixmap references to QImage This hopefully fixes #1108. * Add comments to explain why we are stashing references.
1 parent c33a76f commit dd05bd0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pyface/ui/qt4/util/image_helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def image_to_bitmap(image):
4545
bitmap : QPixmap
4646
The corresponding QPixmap.
4747
"""
48-
return QPixmap.fromImage(image)
48+
bitmap = QPixmap.fromImage(image)
49+
# keep a reference to the QImage to ensure underlying data is available
50+
bitmap._image = image
51+
return bitmap
4952

5053

5154
def bitmap_to_image(bitmap):
@@ -166,6 +169,7 @@ def array_to_image(array):
166169
elif channels == 4:
167170
image = QImage(data.data, width, height, bytes_per_line,
168171
QImage.Format.Format_ARGB32)
172+
# keep a reference to the array to ensure underlying data is available
169173
image._numpy_data = data
170174
return image
171175

0 commit comments

Comments
 (0)