I'm looking to make some custom gui elements. Has anyone had success using pyside to use Qt to communicate with Blender?
-
If it is meant as a part of Blender script/plugin why not use the Blender GUI? Surely this should integrate better. – elmo Apr 08 '14 at 11:41
-
I have my reasons. I'm making an exporter that links to a webservice, not a file. I don't think it's unreasonable that I would want additional gui elements. – Ben L Apr 09 '14 at 14:17
2 Answers
There is at least a video showing someone compiled PyQt into Blender:
And a facebook post:
https://www.facebook.com/cgtutorials/posts/521688517904188?stream_ref=10
So it seems possible, at least with a modified Blender binary.
- 29,298
- 3
- 89
- 128
-
1Watching this video is one of the inspirations for asking this question. – Ben L Apr 14 '14 at 17:51
-
I have tried to get PySide working inside Blender, but i have had trouble getting PySide working correctly in python 3.4 standalone, so i gave up on PySide and moved to PyQt4.
First of all, i have it working on mac OSX 10.8 with blender 2.71. but i would say the process below would be almost the same on linux, but for windows may be easier, as you can download QT4 and PyQT4 binaries
i would suggest setting up a Virtual environment, as i previously had issues with different versions of python running on my machine, and it mucked up the install path, and version of python used to compile PyQt.
https://pypi.python.org/pypi/virtualenv
You need to make sure you install PyQT with the exact version of python that blender is using (2.71 uses 3.4, 2.70 uses 3.3)
I used the following versions.
- Python 3.4.1
- Qt 4.8.6
- pyQT 4.11.1
Once you have the correct python version, and virtualenv set up and working this is the code i use inside blender to open a PyQT window.
import sys
sys.path.append('*venv directory* /py3.4/lib/python3.4/site-packages')
import bpy
from PyQt4 import QtGui, QtCore
class ExampleQtWindow(QtGui.QDialog):
def __init__(self):
super(ExampleQtWindow, self).__init__()
self.mainLayout = QtGui.QVBoxLayout(self)
self.buttonLayout = QtGui.QHBoxLayout()
self.CreateButton = QtGui.QPushButton("print info")
QtCore.QObject.connect(self.CreateButton, QtCore.SIGNAL('clicked()'), self.testCommand)
self.mainLayout.addWidget(self.CreateButton)
self.setLayout(self.mainLayout)
def testCommand(self):
print(bpy.data.objects)
# register class stuff
class PyQtEvent():
_timer = None
_window = None
def execute(self):
self._application = QtGui.QApplication.instance()
if self._application is None:
self._application = QtGui.QApplication([''])
self._eventLoop = QtCore.QEventLoop()
self.window = ExampleQtWindow()
self.window.show()
print("running in background")
new_window = PyQtEvent()
new_window.execute()
- 921
- 4
- 8