Problem PyQt into Blender

Hello,
I create an interface with some buttons with PyQt5.
When i run the command: blender file.blend -P script.py, I receive this:



Can you help me to solve this problem?
Thanks

You should post the script! But my guess is that you shouldn’t be trying to run the Qt application in the same thread. The Qt application is just taking over and stopping Blender from loading the UI or doing anything else for that matter. Also if you try and close the Qt application it will probably terminate Blender which isn’t something you would want to have happen.

i don’t understand you. can you explian more please

Well to put it simply all application have a main application loop, Blender has one and your Qt application has one. When you run your script Blender loads up and when it executes your script your Qt application’s main loop gets entered and prevents Blender from doing anything else. So to over come this you can either launch your Qt application as a completely separate process or run it in a different thread.

https://docs.python.org/3.5/library/subprocess.html
https://docs.python.org/3.5/library/threading.html

https://www.tutorialspoint.com/python3/python_multithreading.htm

this is the simple interface PyQt:

import bpy
import sys
from PyQt5.QtWidgets import (QWidget, QToolTip, 
    QPushButton, QApplication)
from PyQt5.QtGui import QFont    
class Example(QWidget):  
    def __init__(self):
        super().__init__()     
        self.initUI()  
    def initUI(self): 
        QToolTip.setFont(QFont('SansSerif', 10))
        self.setToolTip('This is a <b>QWidget</b> widget')  
        btn = QPushButton('Button', self)
        btn.setToolTip('This is a <b>QPushButton</b> widget')
        btn.resize(btn.sizeHint())
        btn.move(50, 50)        
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Tooltips')    
        self.show()    
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

To prevent Blender of freezing when running a Qt application, you can also run it in a modal operator and update it with QEventLoop().
I made an example here : https://github.com/vincentgires/blender-scripts/blob/master/addons/qt_integration/init.py

To show that’s working: https://www.youtube.com/watch?v=HONYC5yRPX4

Thank you for your reply. your project is very interesting.
Can you tell me how can i install qt_integration in blender, please?
I add the qt_integration folder to .zip and i install it as addon. but I don’t know where can i found it…

This is just an example. You can install it like any other addons but it will mostly do nothing more than showing an empty Qt window. You can use that code to see how I used Qt inside Blender and how modal operator is working with QEventLoop().

This was inspired from SideFX documentation and topics I found in BlenderArtists.
https://www.sidefx.com/docs/houdini13.0/hom/cookbook/pyqt/

I want juste test your addons. I install it but i don’t know how to show this empty Qt window.
Can you tell me how execute your example, please?

I don’t know your level in scripting but maybe you should start learning Python and bpy module.

What is your goal with Qt inside Blender? It probably more than enough to use the available tools provided by the API which is very well integrated along other Blender tools. I can understand it but I’m curious to know why you need it?

Anyway, if you want to try the custom Qt window, just launch the operator.

I have a good level in python and i already create a script into blender. I want to create an interface PyQt that run my script functions. UI Blender is too classic … that’s why i want to do it with PyQt.

I look just how to embed PyQt into scene 3D of blender. i test your example but i don’t found the interface. can you tell me where can i found it please?

I have a good level in python and i already develop a script in blender i want just an interface Qt that run my script functions. UI Blender is too classic.
I look just how to embed PyQt into scene 3D of blender. i test your example but i don’t found the interface. can you tell me where can i found it please?

The operator label is “PyQt Event Loop”. Just execute it (with space key).
Don’t forget to set PyQt path in config.py.

What kind of Qt widgets do you want to use inside Blender? I’m curious.

I automated 3D modeling tasks and i want to create a QT Widget with some buttons to execute th script.
I don’t understand how can execute your example. have you a tutorial or some thing to expalin it to me please?
i try to execute this script: http://pasteall.org/45859/python
but it doesn’t run a widget…

To run my example, just enable the addon and execute the operator. I can’t tell more than that.

But for your script, why don’t you use panels on the side to put buttons that execute your scripts? There is even a dialog box implemented in bpy api: https://docs.blender.org/api/blender_python_api_current/bpy.types.Operator.html

How to execute the operator?

https://docs.blender.org/manual/es/dev/interface/controls/templates/operator_search.html

@Py3D
Let me just say one of the reason I switched from Maya to Blender was because they changed to Qt. Qt is great from a programmers perspective but it’s not particularly light weight or fast to load when compared to Blender’s or Unity’s for example. From a users point of view I just what my application’s UI to load fast and use as little amount of memory as possible.

Do you think Blender and Unity would be as popular as they are today if they had used Qt for their UI’s? Taking into account the huge number of casual users out there that are probably still running on budget computers that were purchased maybe five or more years ago.

I’m not say Qt can’t be implement well, I think Nuke’s Qt UI implementations is probably a good example that it can be. However it’s never going to be as fast or have as lower memory footprint as Blender’s homegrown UI.

So honestly, IMHO any person that thinks Unity or Blender has a bad/old UI is really only looking at it from a purely visual perspective and as such they are probably not doing any actually work within the application. Sure you could argue that the design layout isn’t as good as it could be but from a UI performance perspective Blender is amazing, and personally I love the design layout too.

So if all you are trying to do in your Qt application is display some basic widgets like buttons, checkboxes etc then really STOP! and just use the Blender UI. If you really dislike the UI then my advice to you is to download the Blender source code learn how to compile and build it and then start modify the UI code yourself.

Anyway I’m really not try to offend you I’m just sharing my dislike of Qt :stuck_out_tongue:

So first off I would whole heartedly agree with 2 points. 1. That the design layout isn’t as good as it should be and 2. If all you’re doing is basic buttons etc then Blender is great.

However when you start making custom widgets of course there is a great advantage of using QT. Secondly Let’s say I’m a plugin developer and make a QT UI for maya that I want to then bring to blender… the ease of being on an industry “standard” (purposefully in quotes) becomes obvious.