How to insert a visual graph in PyQt?

I am trying to embed a visual plot (more precisely, Vispy SceneCanvas) as a QWidget in PyQt4. I would suggest that the answer would be something like this:

from PyQt4.QtCore import * from PyQt4.QtGui import * import vispy.mpl_plot as plt app = QApplication(sys.argv) win = QMainWindow() plt.plot([1,2,3,4], [1,4,9,16]) vispyCanvas=plt.show()[0] win.setCentralWidget(vispyCanvas) 

However, when I try to do this, the last line gives me the expected error that vispyCanvas is a SceneCanvas type and not a QWidget type. When I print(vispyCanvas) , it outputs <Vispy canvas (PyQt4 (qt) backend) at 0x142bcb00L> , so I suspect that it can be considered either one of its attributes as a QWidget object.

+5
source share
1 answer

The answer is simple:

 win.setCentralWidget(vispyCanvas.native) 

While vispy uses Qt as its backend, then Canvas.native refers to the base QGLWidget .

+9
source

Source: https://habr.com/ru/post/1211042/


All Articles