1

How do I display a 2D numpy.ndarray as a collection of pixel values on a QGraphicsView? pylab.imshow() would typically be used at this point if I wasn't trying to make a GUI.

frame = array([[ 56.,  57.,  58., ...,  58.,  58.,  58.],
       [ 52.,  58.,  58., ...,  56.,  57.,  59.],
       [ 56.,  55.,  58., ...,  57.,  57.,  58.],
       ..., 
       [ 53.,  55.,  55., ...,  54.,  54.,  53.],
       [ 54.,  57.,  56., ...,  53.,  54.,  59.],
       [ 55.,  57.,  54., ...,  56.,  58.,  57.]])

My attempt:

scene = QGraphicsScene(self)                                            
scene.addPixmap(QPixmap.fromImage(qimage2ndarray.array2qimage(frame)))
view = self.graphicsView(scene, self) # Error from this line
self.graphicsView = QtGui.QGraphicsView(scene, self)
view.show()

TypeError: 'QGraphicsView' object is not callable. I want to specifically add the scene to the QGraphicsView named graphicsView that was generated by QT Designer. If I replace the line causing the error with the following

view = QtGui.QGraphicsView(scene, self)

Then the image displays, but in the top left of the QMainWindow on top of my other widgets. How do I restrict placement to a specific QGraphicsView?

Frikster
  • 2,755
  • 5
  • 37
  • 71
  • Possibly the same as this question? http://stackoverflow.com/questions/9794019/convert-numpy-array-to-pyside-qpixmap – DavidG Feb 12 '16 at 12:32
  • Wow. Looking at my 2 hour long search history, I never used 'numpy,' only "matrix/array to QGraphicsView" and variations. Anyway, I amended my question. Made progress with that link, but still stuck. – Frikster Feb 12 '16 at 13:31

1 Answers1

1

Playing around I find this minimalist solution:

scene = QGraphicsScene(self)            
scene.addPixmap(QPixmap.fromImage(qimage2ndarray.array2qimage(frame)))
self.graphicsView.setScene(scene)
Frikster
  • 2,755
  • 5
  • 37
  • 71