如何在特定的QGraphicsView上显示2D numpy.ndarray作为像素值的集合?

时间:2016-02-12 12:29:55

标签: python arrays qgraphicsview qgraphicsscene

如何在(df$B <- Reduce(paste, as.character(df$A), accumulate = TRUE)) # [1] "banana" "banana boats" "banana boats are" "banana boats are awesome" 上将2D numpy.ndarray显示为像素值的集合?如果我没有尝试制作GUI,通常会使用QGraphicsView

pylab.imshow()

我的尝试:

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.]])

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() 。我想专门将场景添加到由QT Designer生成的名为TypeError: 'QGraphicsView' object is not callable的{​​{1}}。如果我用以下

替换导致错误的行
QGraphicsView

然后显示图像,但在graphicsView的左上角显示我的其他小部件。如何将展示位置限制为特定view = QtGui.QGraphicsView(scene, self)

1 个答案:

答案 0 :(得分:0)

在我身边找到这个简约的解决方案:

scene = QGraphicsScene(self)            
scene.addPixmap(QPixmap.fromImage(qimage2ndarray.array2qimage(frame)))
self.graphicsView.setScene(scene)