it looks like QSCrollArea.setWidget() does a lot more than what it seems. And seems to be partially related to my issue. E.g.
*If the scroll area is visible when the widget is added, you must show() <https://doc.qt.io/qt-5/qwidget.html#show> it explicitly.* or *Note that You must add the layout of widget before you call this function; if you add it later, the widget will not be visible - regardless of when you *show() <https://doc.qt.io/qt-5/qwidget.html#show>* the scroll area. In this case, you can also not *show() <https://doc.qt.io/qt-5/qwidget.html#show>* the *widget *later.* As a temp solution, I use a QStackedWidget() to keep all my widgets and display them when needed, but I would really like to understand why my widget is destroyed despite the reparenting, in the example above cheers Le jeudi 15 octobre 2020 à 09:13:42 UTC-4, vince touache a écrit : > hello, > > I have this good old *internal C++ object already deleted *and can't > understand where it comes from > To summarize, I have a QMainWindow with a QScrollArea, and I want to > parent/unparent widgets into this QScrollArea. Ofc I make sure to re-parent > the widget I'm about to remove, to make sure it never gets unparented and > garbage collected, but it doesn't change anything.... > > Since I still don't know how to format code on google groups (yay \o/), I > updated some code on github <https://github.com/fruityvince/debug> if > someone wants to try it , and here is a snippet to reproduce the error > > import main;import foo > m = main.Main() # this is my main window > m.show() > # now I create 2 widgets, and I want to display the first one in my > scrollArea, then the second, then come back on my first > bar1 = foo.Bar("bar1") > bar2 = foo.Bar("bar2") > > # now I parent it to my scrollArea > m.something_triggered(bar1) > m.something_triggered(bar2) # this is where bar1 gets deleted, even though > i reparent it before replacing with bar2 > >>> # RuntimeError: Internal C++ object (PySide2.QtWidgets.QLabel) already > deleted. # > > Can anyone explain me why / how my bar1 gets deleted, even though I parent > it to my mainWindow to prevent garbage collection? > > Thank you > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a6fef101-6378-4b3d-9bac-00c95936afd3n%40googlegroups.com.