Chris Roda

ProfessorChris

About Me

専門知識
Not Specified
Location
Not Specified
ウェブサイト

Connect

Recent Forum Posts

Fundamental PySide2 2022年9月26日8:31

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 2022年9月23日7:24

Thank you, Vic_lc!

I just noticed your reply.

This is the last piece of the puzzle.

Much appreciated!

Default $HFS Locations 2022年9月19日7:22

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