A PySide2 Wrapper for Blender 2.8x

The game-development Technical Artist community has been working on a PySide2 wrapper for Blender 2.8 It’s open source (MPL licensed). You can find it here:

Users must add PySide2 to their Blender installations.Windows users will also need to add the win32gui package. Both of these prerequisites are available via pip from PyPi.

There is currently support for Windows and MacOS. Linux support has not been added yet.

BQT consists of a Blender startup script that finds the running Blender process and re-parents it to a QApplication instance. From then PySide2 widgets can be created and properly parented to the window.

It’s not 100% yet, but is very workable. Users and contributors discuss it on the #blender channel in the Tech-ArttistsOrg Slack

6 Likes

Hi,

I was researching this a few weeks back. One proposal that would simplify a lot of the issues between different platforms is if the Blender windowing system abstraction (Ghost?) could bind and hand off the main window’s OS-dependent handle/pointer as a void pointer in Python for whatever Qt bindings you want to use (you can then inject it into Qt). This is solely for making the main Blender window be a parent and the Qt window sit above or minimize with the Blender window, and is common practice in DCC apps which don’t use Qt.

Cheers

1 Like

Hi! Very interesting project!
Could you please explain benefits of using it with blender? As far as I understand this is the way of making custom QT tools that connects to blender?

Yes, it is exactly that. With BQT you can create Qt for Python (aka PySide2) dialogs and correctly parent them to the Blender window. They have a valid QT main-loop so you can set them to be modal and they will properly block other Blender operations until you close the dialog.

As most other well-used DCC apps (3ds Max, Maya, Photoshop, Substance, etc…) follow the VFX reference platform and/or use Qt as their windowing toolkit BQT makes it easier to develop a UI framework and ease creating similar pipeline tools within different DCC target applications.

1 Like

Hey

Thanks so much for contribution !

But can you do any sort of manual/step by step guide on how to do hello world window/dock window or something like that… ?

Ty

Here is a very small module I wrote to integrate qt widgets into blender without blocking the blender window. No parent window support but it can lay on top with a flag, so not a real problem. It’s been using for years now in the studio I’m working and this is very stable.

1 Like

Hi Dariusz,

I honestly thought another community member had put a hello world example in the Git Hub repository. I’ve fixed that oversight and added one to the repo. You can find it here:

1 Like

I was recently messing with it, well this + 3 other libs I found. I havent had a chance to test your one yet, but in other lib when ever I had Qt window open and I resize blender, blender would just hang and die, do you also experience that issue in your library ? / Same thing happens when adding fileDialog and blender goes bananas :x

Hello. I´m trying to build a pipeline system to work online and i have setup a common directory where we stored all the pyModules. I have been testing the bqt installed locally with pip and it works perfectly. However, if I store the pyModules and the startup file in the common directory, when the startup is executed, it can’t find the modules.

Traceback (most recent call last):
      File "D:\Programas\Blender Foundation\Blender 2.93\2.93\scripts\modules\bpy\utils\__init__.py", line 136, in _test_import
        mod = __import__(module_name)
      File "D:\Proyectos\BlenderPipe\blenderpipetools\startup\bqt_startup.py", line 1, in <module>
        import bqt
    ModuleNotFoundError: No module named 'bqt'

Do you have some idea of how can setup the bqt in a common repository?
I’m setting the variable BLENDER_USER_SCRIPTS to set the common path where we store the modules and startup files.
When Blender has been opened, the pymodules can be imported, but the startup couldn’t be executed in the startup process and now the widgets can not be parented to the blender window.

Traceback (most recent call last):
 File "\Text", line 2, in <module>
  File "D:\Proyectos\BlenderPipe\blenderpipetools\modules\bqt\hello_world.py", line 46, in demo
    main_window = QApplication.instance().blender_widget
AttributeError: 'NoneType' object has no attribute 'blender_widget'
Error: Python script failed, check the message in the system console
2 Likes

Hey @JorgeHI100,
it’s important that not only the modules are shared, but that you also run bqt_startup.py on blender startup.
This can easily be done by putting it in a folder named startup, which is in your script path.

example:
BLENDER_USER_SCRIPTS = c:/my_scripts
c:/my_scripts/modules/bqt → the bqt module goes in your shared modules folder
c:/my_scripts/startup/bqt_startup.py → the bqt startup script goes in the startup folder

this file was missing from the repo untill recently, and was only included in the pip install.
so you might have missed it