is there a way to get the main editor window (or any other editor window) with Python, to use it as a parent for a Qt or PySide application?
I just started looking into the Shotgun integration code, but couldn’t find a solution.
I found a solution and will answer it here. Hopefully it will be useful for some people.
There is a python function called
unreal.parent_external_window_to_slate()
with this function, you can parent any window to the unreal window. We used it to parent our pipeline (PyQt) Qt widgets to Unreal.
After parenting external windows to Unreal, they will automatically minimize/ maximize and shut down with Unreal. Furthermore they will be displayed above the Unreal window, on which you parented it.
You get the window Id from (PyQt) with the following function:
YourWidget.winId()
Just use the resulting Id as input of the unreal function:
I do have a follow up question:
How do you send commands from the connected Qt window to Unreal?
The UI still evaluates using the external python exe you used to create it with.
long time ago …
Haven’t used Python for Unreal for a while now. But I noticed, that there is now a new description for the function and it takes 2 arguments now (not sure if this is new or if it was not documented in 2018)
It still stays in memory ( calling qt_app.allWidgets() returns increasing number of widgets). I know this has something to do with the fact that I am not calling qt_app.exec() ( this will make main loop for my window and freeze unreal which is unwanted behavior). Does anyone know how to remove widgets from the memory in unreal, or what will be the general approach?
I’m interested in this too, but I would prefer a Native Gui solution in unreal-python.
What I do at the moment:
def tool_function_called_in_a_button():
app = QtWidgets.QApplication.instance() or QtWidgets.QApplication( sys.argv ) # unreal crashes without this
global window # window disappears without this
window = QtWidgets.QWidget() # crash without app line
window.show()
unreal.parent_external_window_to_slate( window.winId() ) # attach to unreal, keep it on top of main window.
after a lot of research, I was unable to properly Delete the object from memory.
Like you said already, best thing I could do was to do widget.close()
which is hiding the widget but not deleting it.