Example code to show Blender and Pyside2 integration
APACHE-2.0 License
You should also check out the bqt repository, for a more complete implementation of Qt with Blender. https://github.com/techartorg/bqt
Example to run Qt/PySide2 applications in Blender, based on Rajiv Sharma's VFX Pipeline video: https://www.youtube.com/watch?v=QYgHyi7jd9c
This is a simplified version of the code shown in the video of Rajiv Sharma. The intend is to make it easy to follow along and discuss the techniques shown.
The functionality of the Qt tool is now limited to only create new cameras and switch to existing cameras.
All other methods are identical to the video (outside of some fixes to get Blender to load the addon).
Put the whole setup into Blender\addons\blender_pyside2_example or your custom scripts/addons path.
In Blender press N in the viewport, and open the VFXPipeline panel on the side. Press the button in the panel to launch the Qt Application.
If you haven't installed PySide2 yet, check "How to install Pyside2 into Blender" further down
The main content here is the QtWindowEventLoop in core.py, which inherits the Blender operator and sets up modal execution with a QEventLoop that is triggered at 120Hz by Blender's window manager.
The actual tool is the CamControllerWindow, (originally inheriting the Ui_Form class, created by Qt designer, simplified here) and QDialog.
The only Blender UI element is CamControllerQtPanel (a regular bpy panel), containing the CustomWindowOperator as a UI button. The CustomWindowOperator is a QtWindowEventLoop Operator. It launches the eventloop and the (Qt) CamControllerWindow.
+ Blender/Addons/Camtools/
| (Camtools is the name of the addon in the video, here: Blender_Pyside2_Example)
+-- __init__.py
| register() and unregister() are in here (Blender addon initialization)
+-- core.py
| QtEventLoop() (this is the most important part)
+-- camController.py
| The actual Blender Addon code and Qt Window
+-- gui/
| +-- main.py
| Originally this was a Designer UI, now just a simple replacement
+-- venv/ (In the video a venv is used, not here)
| +-- Lib/
| | +-- site-packages/
| | | +-- PySide2
| | | +-- shiboken2
| | +-- pyvenv.cfg
Rajiv Sharma did all the difficult work on this, and graciously shared his knowledge in his VFX Pipeline video (see link at the top of this document). This repository is just to help show how the implementation is done and contains only minor fixes.
The video in turn is probably based on Vincent Gires work here: https://github.com/vincentgires/blender-scripts/tree/master/scripts/addons/qtutils