Skip to content

RawImageGLWidget: update uploaded state on cleanup#3043

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-cleanup
Jun 4, 2024
Merged

RawImageGLWidget: update uploaded state on cleanup#3043
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-cleanup

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Jun 4, 2024

cleanup (followed by initializeGL) will be called if QOpenGLWidget gets reparented (and not just during application shutdown)

in such a case, state variables need to be maintained.

A script that demonstrates the scenario:

  1. RawImageGLWidget is first created parent-less and show()n.
    • this causes RawImageGLWidget to be a top-level window and triggers creation of an OpenGL context
  2. next it is made a child of QMainWindow.
    • this causes RawImageGLWidget to no longer be a top-level window and triggers the creation of a new OpenGL context

Without this PR, a black window will be displayed.

import sys

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets

pg.setConfigOption('imageAxisOrder', 'row-major')

qimage = QtGui.QImage(sys.argv[1])
qimage.convertTo(QtGui.QImage.Format.Format_RGBA8888)
image = pg.functions.ndarray_from_qimage(qimage)

pg.mkQApp()
win = QtWidgets.QMainWindow()
img = pg.RawImageGLWidget()
img.setImage(image)
img.show()  # force a re-parent
win.setCentralWidget(img)
win.destroyed.connect(img.cleanup)
win.resize(640, 480)
win.show()
pg.exec()

cleanup (followed by initializeGL) will be called if QOpenGLWidget gets
reparented (and not just during application shutdown)

in such a case, state variables need to be maintained.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jun 4, 2024

Just ran this on macOS, confirmed it's working.

@j9ac9k j9ac9k merged commit bb306cf into pyqtgraph:master Jun 4, 2024
@pijyoi pijyoi deleted the fix-cleanup branch June 4, 2024 11:35
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

Successfully merging this pull request may close these issues.

2 participants