Moving child widgets between QTabWidgets?
Matic Kukovec
kukovecmatic at hotmail.com
Wed Jan 18 16:34:48 GMT 2023
removeTab() does not reparent the widget, you need to call setParent(None) after removeTab.
That is exactly what I do not want, as setParent(None) will delete the underlying widget. I want it moved to the other tabwidget.
You also shouldn't need to set the old and new tab widgets to None.
David
I know, I just copied my development application's behaviour.
Matic
________________________________
From: David Boddie <david at boddie.org.uk>
Sent: Wednesday, January 18, 2023 5:23 PM
To: pyqt at riverbankcomputing.com <pyqt at riverbankcomputing.com>
Subject: Re: Moving child widgets between QTabWidgets?
On Wed Jan 18 13:48:58 GMT 2023, Matic Kukovec wrote:
> I managed to get a self-contained example which throws the same error as my
> development code:
I think you should avoid reparenting the old QTabWidget to None before you
move the pages into the new QTabWidget.
Try this version of the switch method:
def switch(self, *args):
widgets = []
old_tab_widget = self.tab_widget
for i in reversed(range(old_tab_widget.count())):
widgets.append((old_tab_widget.widget(i),
old_tab_widget.tabText(i)))
old_tab_widget.removeTab(i)
new_tab_widget = QTabWidget()
for widget, tab_text in widgets:
new_tab_widget.addTab(widget, tab_text) # <- ERROR THROWN HERE
for i in reversed(range(self.centralWidget().count())):
self.centralWidget().widget(i).setParent(None)
#old_tab_widget = None
#self.tab_widget = None
self.centralWidget().addWidget(new_tab_widget)
self.tab_widget = new_tab_widget
You also shouldn't need to set the old and new tab widgets to None.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20230118/8a2dee29/attachment-0001.htm>
More information about the PyQt
mailing list