I'm trying to launch a UI in H16 from a shelf tool using PySide2's QUiLoader. I'm basically following the code example from this page [sidefx.com], but with a .ui file rather than building it all myself (it's a pretty large complex UI). The problems I'm having are the following:
- If I implement ui.show() outside of the class, the UI shows up as a blank window.
- If I implement self.ui.show() inside of the class, the UI shows up properly, but I can't seem to be able to close the window using any of my buttons - self.ui.buttonName.clicked.connect(self.close) does nothing. Plus, this seems incorrect anyways.
- Implementing a closeEvent method in the class as suggested here [sidefx.com] does not close the window, it just removes the inherited stylesheet formatting - leaving my ui ugly.
What am I doing wrong? As far as I can tell, I'm following all the provided examples for running PySide inside Houdini. My abbreviated code is:
import hou from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools class HDAManager(QtWidgets.QWidget): def __init__(self, parent=None): super(HDAManager, self).__init__(parent) ui_file = QtCore.QFile('/path/to/file.ui') ui_file.open(QtCore.QFile.ReadOnly) self.ui = QtUiTools.QUiLoader().load(ui_file, parentWidget=self) ui_file.close() self.makeConnections() # ... more code ... # def makeConnections(self): self.ui.cancelButton.clicked.connect(self.close) self.ui.otherCancelButton.clicked.connect(self.closeEvent) def closeEvent(self, event): self.setParent(None) def run(): window = HDAManager() window.setParent(hou.qt.mainWindow(), QtCore.Qt.Window) window.show()