Search code examples
pythonpython-3.xpyqtpyqt5vispy

How to embed vispy canvas in PyQt5 frame


Hey I want to embed the output window of vispy canvas in my pyqt5 generated Gui. I don't know much about vispy so please help thanks in advance.


Solution

  • As long as vispy is using Qt as backend, you must use .native, this parameter will make the canvas use QGLWidget, for example:

    from PyQt5.QtWidgets import *
    import vispy.app
    import sys
    
    canvas = vispy.app.Canvas()
    w = QMainWindow()
    widget = QWidget()
    w.setCentralWidget(widget)
    widget.setLayout(QVBoxLayout())
    widget.layout().addWidget(canvas.native)
    widget.layout().addWidget(QPushButton())
    w.show()
    vispy.app.run()