I have a PyQtGraph widget that I am using to display processed arrays from a framegrabber. A thread acquires these puts these data into a queue and another thread gets these data from the queue and calls update(data) on my widget. Data is a relatively small (400*100) numpy array
class BScanView(PyQtG.GraphicsLayoutWidget):
def __init__(self, aspect=0.5):
super().__init__()
self.aspect = aspect
self.viewbox = self.addViewBox(row=1,col=1)
self.viewbox.setAspectLocked()
self.image = PyQtG.ImageItem()
self.viewbox.addItem(self.image)
def update(self, data):
self.image.clear()
self.image.setImage(data, autoLevels=False, levels=(-100, -2))
QtGui.QGuiApplication.processEvents()
This works for awhile but randomly crashes the ImageItem. The rest of the GUI works fine for subsequent use but the above widget is unresponsive.
It's difficult to say because I cannot reproduce your issue but I can think of a few potential causes.
data
array is shared between the threads and updated incorrectly. Try making a copy of the array before you set it in the image with self.image.setImage(np.copy(data),...
GraphicsLayoutWidget
is a decendent of QWidget
and therefore has an update
method. You override it with a different signature. I don't know PyQt handles this exactly but try renaming your method to updateImage
and see if it makes a difference.processEvents
? You should not need it here.Your code example is not an MVCE in the sense that it's not complete; information is missing on how the data is created in the other thread. Hundred percent completeness is not always achievable (external libraries and such), but try to make it as complete as possible. To make a complete, minimal and verifiable example can be a fair amount of work, but the more effort you put into it, the more answers you will receive and the better they will be.