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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With