Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed vispy graph in PyQt?

I'm trying to embed a vispy plot (more specifically, a Vispy SceneCanvas) as a QWidget into PyQt4. I would presume 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 this the last line gives me the expected error that vispyCanvas is type SceneCanvas and not of type QWidget. When I print(vispyCanvas), it prints out <Vispy canvas (PyQt4 (qt) backend) at 0x142bcb00L>, which is why I suspect that it should be possible to treat it or one of its attributes as a QWidget object.

like image 879
Kyle Ellefsen Avatar asked Jan 13 '15 22:01

Kyle Ellefsen


1 Answers

The answer is simple:

win.setCentralWidget(vispyCanvas.native)

As long as vispy is using Qt as its backend, then Canvas.native refers to the underlying QGLWidget.

like image 93
Luke Avatar answered Nov 01 '22 09:11

Luke