我没有 Maya 或 Houdini,所以我帮不了你太多。
根据https://www.sidefx.com/docs/houdini/hom/cb/qt.html
看起来您可以访问 Houdini 的主窗口。窗口被复制或删除的主要原因是python如何保留对window_C的引用。您可以通过访问主 Houdini 窗口来保留引用以一遍又一遍地显示相同的小部件。
在下面的示例中,我们以不同的方式使用引用。您可能不需要您的代码
self.setParent(hou.qt.mainWindow(), QtCore.Qt.Window)
创建一次小部件,然后一遍又一遍地显示相同的小部件。
import hou
# Create the widget class
class someWidget(QtWidgets.QWidget):
def __init__(self, parent=None, flags=QtCore.Qt.Window): # Note: added parent as an option
super(someWidget,self).__init__(parent, flags)
...
MAIN_WINDOW = hou.ui.mainQtWindow()
try:
MAIN_WINDOW.window_C.show()
except AttributeError:
# Widget has not been created yet!
# Save the widget reference to an object that will always exist and is accessible
# parent shouldn't really matter, because we are saving the reference to an object
# that will exist the life of the application
MAIN_WINDOW.window_C = someWidget(parent=MAIN_WINDOW)
MAIN_WINDOW.window_C.show()
删除前一个窗口并创建一个新窗口。
import hou
# Create the widget class
class someWidget(QtWidgets.QWidget):
def __init__(self, parent=None, flags=QtCore.Qt.Window): # Note: added parent as an option
super(someWidget,self).__init__(parent, flags)
...
MAIN_WINDOW = hou.ui.mainQtWindow()
# Hide the previous window
try:
MAIN_WINDOW.window_C.close()
MAIN_WINDOW.window_C.deleteLater() # This is needed if you parent the widget
except AttributeError:
pass
# Create the new Widget and override the previous widget's reference
# Python's garbage collection should automatically delete the previous widget.
# You do not need to have a parent!
# If you do have a parent then deleteLater above is needed!
MAIN_WINDOW.window_C = someWidget() # Note: We do not parent this widget!
MAIN_WINDOW.window_C.show()
另一个资源显示您可以从页面级别变量访问上一个小部件。https://echopraxia.co.uk/blog/pyqt-in-houdinimaya-basic这是可能的,但对我来说似乎很奇怪。该模块应该只导入一次,因此页面级变量“my_window”不应该存在。但是,听起来 Houdini 插件系统要么重新加载 python 脚本,要么重新运行导入。如果每次您从脚本的导入中显示一个新窗口时都是这种情况,那么您正在创建一个新窗口。如果上一个窗口没有正确关闭和删除,Houdini 可能会出现越来越严重的内存问题。
try:
my_window.close()
except (NameError, Exception):
pass # Normal python would always throw a NameError, because my_window is never defined
my_window = MyWindow()
#This is optional you can resize the window if youd like.
my_window.resize(471,577)
my_window.show()
PySide6
https://www.sidefx.com/docs/houdini/hom/cb/qt.html
页面底部显示了如何使用 PyQt5。这同样适用于 PySide6。Houdini 恰好与 PySide2 一起提供。