Fundamental PySide2

   977   0   2
User Avatar
Member
16 posts
Joined: March 2020
Offline
I am not sure WHY this happens this way. Maybe a Dev or someone with a lot of GUI experience can help out.

I'm trying to create a very simple PySide2 window from the script tool bar:
from PySide2.QtWidgets import QWidget

window = QWidget()
window.show()

When I execute the tool from the script bar, a window briefly appears and disappears. I am guessing that the window is not attached to the Houdini main window and is removed when Python performs its garbage collection.

In order to attach the window to the Houdini window I use hou.qt.MainWindow() to give it a parent to attach to:
from PySide2.QtWidgets import QWidget
from hutil.Qt import QtCore


window = QWidget()
window.setParent(hou.qt.mainWindow(), QtCore.Qt.Window)
window.show()

The window remains until I close it or Houdini!

The part I am confused about it is if I put the window into a class, I do not need to directly attach the window to the Houdini window and the new window persists:
from PySide2.QtWidgets import QWidget

class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()
        
window = MyWidget()
window.show()

Can anyone explain why we do not to directly parent to the Houdini window when called from within a class?
  • Quick Links