<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div><span style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<div class="elementToProof"><span style="font-size:12pt;background-color:rgb(255, 255, 255)" class="elementToProof">
<blockquote style="border-color:rgb(200, 200, 200);border-left:3px solid rgb(200, 200, 200);padding-left:1ex;margin-left:0.8ex;color:rgb(102, 102, 102)">
<span class="ContentPasted1">removeTab() does not reparent the widget, you need to call setParent(None) after removeTab.</span></blockquote>
</span></div>
<div class="elementToProof"><span style="font-size:12pt;background-color:rgb(255, 255, 255)"><span class="ContentPasted1">That is exactly what I do not want, as
<i><b><span style="font-size:12pt;background-color:rgb(255, 255, 255)"><span style="background-color:rgb(255, 255, 255)"><span class="ContentPasted1 ContentPasted2">setParent(None)</span></span></span></b></i><b><span style="font-size:12pt;background-color:rgb(255, 255, 255)"><span style="background-color:rgb(255, 255, 255)"><span class="ContentPasted1 ContentPasted2"></span></span></span></b><span style="font-size:12pt;background-color:rgb(255, 255, 255)"><span style="background-color:rgb(255, 255, 255)"><span class="ContentPasted1 ContentPasted2">
will delete the underlying widget</span></span></span>. I want it moved to the other tabwidget.</span></span><font size="2"><span style=""><br>
</span></font></div>
<blockquote style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);" itemscope="" itemtype="https://schemas.microsoft.com/QuotedText">
<div><font size="2"><span style="font-size:11pt" class="ContentPasted0">You also shouldn't need to set the old and new tab widgets to None.</span></font></div>
<div><br>
</div>
<font size="2"><span style="font-size:11pt" class="ContentPasted0"></span></font>
<div><font size="2"><span style="font-size:11pt" class="ContentPasted0">David</span></font><br>
</div>
</blockquote>
<div class="elementToProof">I know, I just copied my development application's behaviour.</div>
<div class="elementToProof"><br>
</div>
<div class="elementToProof">Matic</div>
</span></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> David Boddie <david@boddie.org.uk><br>
<b>Sent:</b> Wednesday, January 18, 2023 5:23 PM<br>
<b>To:</b> pyqt@riverbankcomputing.com <pyqt@riverbankcomputing.com><br>
<b>Subject:</b> Re: Moving child widgets between QTabWidgets?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Wed Jan 18 13:48:58 GMT 2023, Matic Kukovec wrote:<br>
<br>
> I managed to get a self-contained example which throws the same error as my<br>
> development code:<br>
<br>
I think you should avoid reparenting the old QTabWidget to None before you<br>
move the pages into the new QTabWidget.<br>
<br>
Try this version of the switch method:<br>
<br>
def switch(self, *args):<br>
widgets = []<br>
old_tab_widget = self.tab_widget<br>
for i in reversed(range(old_tab_widget.count())):<br>
widgets.append((old_tab_widget.widget(i), <br>
old_tab_widget.tabText(i)))<br>
old_tab_widget.removeTab(i)<br>
<br>
new_tab_widget = QTabWidget()<br>
for widget, tab_text in widgets:<br>
new_tab_widget.addTab(widget, tab_text) # <- ERROR THROWN HERE<br>
<br>
for i in reversed(range(self.centralWidget().count())):<br>
self.centralWidget().widget(i).setParent(None)<br>
#old_tab_widget = None<br>
#self.tab_widget = None<br>
<br>
self.centralWidget().addWidget(new_tab_widget)<br>
self.tab_widget = new_tab_widget<br>
<br>
You also shouldn't need to set the old and new tab widgets to None.<br>
<br>
David<br>
<br>
<br>
</div>
</span></font></div>
</body>
</html>