From 6d267f21b68d63c2548fbdfb96ab52b677baf8e5 Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Wed, 23 Feb 2022 16:55:24 +0000 Subject: [PATCH 1/2] Fix QPixmap references to QImage This hopefully fixes #1108. --- pyface/ui/qt4/util/image_helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyface/ui/qt4/util/image_helpers.py b/pyface/ui/qt4/util/image_helpers.py index 2d0f6be37..f2b8d0c40 100644 --- a/pyface/ui/qt4/util/image_helpers.py +++ b/pyface/ui/qt4/util/image_helpers.py @@ -45,7 +45,9 @@ def image_to_bitmap(image): bitmap : QPixmap The corresponding QPixmap. """ - return QPixmap.fromImage(image) + bitmap = QPixmap.fromImage(image) + bitmap._image = image + return bitmap def bitmap_to_image(bitmap): From a751eab27b07597f20342a7a4fb08d0b713ef84c Mon Sep 17 00:00:00 2001 From: Corran Webster Date: Thu, 24 Feb 2022 10:19:17 +0000 Subject: [PATCH 2/2] Add comments to explain why we are stashing references. --- pyface/ui/qt4/util/image_helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyface/ui/qt4/util/image_helpers.py b/pyface/ui/qt4/util/image_helpers.py index f2b8d0c40..7d863178f 100644 --- a/pyface/ui/qt4/util/image_helpers.py +++ b/pyface/ui/qt4/util/image_helpers.py @@ -46,6 +46,7 @@ def image_to_bitmap(image): The corresponding QPixmap. """ bitmap = QPixmap.fromImage(image) + # keep a reference to the QImage to ensure underlying data is available bitmap._image = image return bitmap @@ -168,6 +169,7 @@ def array_to_image(array): elif channels == 4: image = QImage(data.data, width, height, bytes_per_line, QImage.Format.Format_ARGB32) + # keep a reference to the array to ensure underlying data is available image._numpy_data = data return image