Chris Roda

ProfessorChris

About Me

Expertise
Not Specified
Location
Not Specified
Website

Connect

Recent Forum Posts

Fundamental PySide2 Sept. 26, 2022, 8:31 a.m.

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?

Default $HFS Locations Sept. 23, 2022, 7:24 a.m.

Thank you, Vic_lc!

I just noticed your reply.

This is the last piece of the puzzle.

Much appreciated!

Default $HFS Locations Sept. 19, 2022, 7:22 a.m.

Thank you, Martin!

It's good to know SideFX is doing it correctly.

The book is an introduction to Python for reluctant artists.
Instead of using Visual Studio, PyCharm or any other programming environment, I founds artists have a much better retention using Houdini as an IDE and have them do exercises on objects and geometry they can see.

I am always looking for reviewers. If you know of anyone who knows Houdini Python, please have them respond to this thread.

Cheers