.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/qt_app.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_app.py: Qt app ------ An example demonstrating a qt app with a wgpu viz inside. Note how the ``rendercanvas.qt.loop`` object is not even imported; you can simply run ``app.exec()`` the Qt way. .. GENERATED FROM PYTHON SOURCE LINES 10-74 .. code-block:: Python # ruff: noqa: N802, E402 import time import importlib # Normally you'd just write e.g. # from PySide6 import QtWidgets # For the sake of making this example Just Work, we try multiple QT libs for lib in ("PySide6", "PyQt6", "PySide2", "PyQt5"): try: QtWidgets = importlib.import_module(".QtWidgets", lib) break except ModuleNotFoundError: pass from rendercanvas.qt import QRenderWidget from rendercanvas.utils.cube import setup_drawing_sync class ExampleWidget(QtWidgets.QWidget): def __init__(self): super().__init__() self.resize(640, 480) self.setWindowTitle("Rendering to a canvas embedded in a qt app") splitter = QtWidgets.QSplitter() self.button = QtWidgets.QPushButton("Hello world", self) self.canvas = QRenderWidget(splitter, update_mode="continuous") self.output = QtWidgets.QTextEdit(splitter) self.button.clicked.connect(self.whenButtonClicked) splitter.addWidget(self.canvas) splitter.addWidget(self.output) splitter.setSizes([400, 300]) layout = QtWidgets.QHBoxLayout() layout.addWidget(self.button, 0) layout.addWidget(splitter, 1) self.setLayout(layout) self.show() def addLine(self, line): t = self.output.toPlainText() t += "\n" + line self.output.setPlainText(t) def whenButtonClicked(self): self.addLine(f"Clicked at {time.time():0.1f}") app = QtWidgets.QApplication([]) example = ExampleWidget() draw_frame = setup_drawing_sync(example.canvas) example.canvas.request_draw(draw_frame) # Enter Qt event-loop (compatible with qt5/qt6) app.exec() if hasattr(app, "exec") else app.exec_() .. _sphx_glr_download_gallery_qt_app.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: qt_app.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: qt_app.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: qt_app.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_