.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/qt/embed.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_qt_embed.py: Embed within a Qt Window ======================== When using the Qt canvas, `Figure.show()` just returns a QWidget that behaves like any other Qt widget. So you can embed it and do other things that you can do with ordinary QWidgets. This example use a simple Plot to display a video frame that can be updated using a QSlider. .. GENERATED FROM PYTHON SOURCE LINES 9-66 .. code-block:: Python # test_example = false from PyQt6 import QtWidgets, QtCore import fastplotlib as fpl import imageio.v3 as iio video = iio.imread("imageio:cockatoo.mp4") # fastplotlib and wgpu will auto-detect if Qt is imported and then use the Qt canvas and output context fig = fpl.Figure() fig[0, 0].add_image(video[0], name="video") def update_frame(ix): fig[0, 0]["video"].data = video[ix] # you can also do fig[0, 0].graphics[0].data = video[ix] # create a QMainWindow main_window = QtWidgets.QMainWindow() # Create a QSlider for updating frames slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal) slider.setMaximum(video.shape[0] - 1) slider.setMinimum(0) slider.valueChanged.connect(update_frame) # put slider in a dock dock = QtWidgets.QDockWidget() dock.setWidget(slider) # put the dock in the main window main_window.addDockWidget( QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, dock ) # calling fig.show() is required to start the rendering loop qwidget = fig.show() # set the qwidget as the central widget main_window.setCentralWidget(qwidget) # set window size from width and height of video main_window.resize(video.shape[2], video.shape[1]) # show the main window main_window.show() # execute Qt app fpl.run() # You can also use Qt interactively/in a non-blocking manner in notebooks and ipython # by using %gui qt and NOT calling `fpl.run()`, see the user guide for more details .. _sphx_glr_download__gallery_qt_embed.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: embed.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: embed.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: embed.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_