Remove tabs from TabWidget
Hi folks , I am using python, PyQt4 and I need to add and remove tabs from a QTabWidget after shown it. The widgets for tab pages are QVTKRenderWindowInteractor from VTK. What do I have to consider for doing this task, for example, flicker, objects deletion, etc.
PS: sorry for my english, it's not so good.
Re: Remove tabs from TabWidget
Re: Remove tabs from TabWidget
yes, I know that, how to delete the widget (QVTKRenderWindowInteractor) from memory, when I try:
interactor = tab_widget.widget(index)
tab_widget.removeTab(index)
interactor.close()
I think PyQt4 or Qt must call the overloaded deleteLater method in the QVTKRenderWindowInteractor (python code) but it does not get called.
Re: Remove tabs from TabWidget
ohh, I forgot, __del__ method is jnot get called either
Re: Remove tabs from TabWidget
You have to check in PyQt docs how to enforce deletion of Qt objects. Can't help you much with that. It's possible that you have to call setParent(None) on each object you want deleted.
Re: Remove tabs from TabWidget
setParent(None) doesn't work, the only thing that work is:
interactor = tab_widget.widget(index)
tab_widget.removeTab(index)
interactor.close()
interactor.deleteLater()
#optionally
del interactor
but if Qt documentation say that when you create a widget with the attribute: WA_DeleteOnClose, when the widget is closed, it will be deleted and I did this when I create the widget:
interactor = QVTKRenderWindowInteractor()
interactor.setAttribute(QtCore.Qt.WA_DeleteOnClose )
Re: Remove tabs from TabWidget
Quote:
Originally Posted by
jmrbcu
setParent(None) doesn't work, the only thing that work is:
Did you check in PyQt docs what works?
Re: Remove tabs from TabWidget
the qt documentation for tabwidget is almost the same so, I don't know where to look.
Re: Remove tabs from TabWidget
I don't mean how to delete pages in tab widget but rather how to delete Qt objects in PyQt in general. I'm sure there is a dedicated call there somewhere to convince the Python garbage collector it should get rid of the object.
Re: Remove tabs from TabWidget
I think that doing:
widget.close()
widget.deleteLater()
del widget
# and optionally this if U really must
import gc
gc.collect()
will do the trick