<div dir="ltr">Hi Matic,<div><br></div><div>Does changing your move_widget function to the following have the desired results you want?</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;line-height:18px;white-space:pre"><div> <span style="color:rgb(86,156,214)">def</span> <span style="color:rgb(220,220,170)">move_widget</span>(<span style="color:rgb(156,220,254)">self</span>):</div><div> <span style="color:rgb(156,220,254)">widget</span> = <span style="color:rgb(156,220,254)">self</span>.<span style="color:rgb(220,220,170)">layout</span>().<span style="color:rgb(220,220,170)">itemAt</span>(<span style="color:rgb(181,206,168)">2</span>).<span style="color:rgb(220,220,170)">widget</span>()</div><div> <span style="color:rgb(156,220,254)">self</span>.<span style="color:rgb(220,220,170)">layout</span>().<span style="color:rgb(220,220,170)">removeWidget</span>(<span style="color:rgb(156,220,254)">widget</span>)</div><div> <span style="color:rgb(156,220,254)">self</span>.<span style="color:rgb(220,220,170)">layout</span>().insertWidget(<span style="color:rgb(181,206,168)">4</span>, <span style="color:rgb(156,220,254)">widget</span>)</div></div></div><div><br></div><div>Best,</div><div><br></div><div>Joshua Willman</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 9, 2022 at 6:48 PM Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">On 09/10/2022 22:57, Matic Kukovec wrote:<br>
> Hi,<br>
> <br>
> My specs: Windows 10 x64, Python3.10 x64, PyQt6.3.1<br>
> <br>
> When clicking the button in the below example, a crash without a<br>
> traceback occurs:<br>
> import sys<br>
> from PyQt6.QtCore import *<br>
> from PyQt6.QtGui import *<br>
> from PyQt6.QtWidgets import *<br>
> <br>
> class TestWindow(QWidget):<br>
> def __init__(self):<br>
> super().__init__()<br>
> self.setFixedSize(640, 480)<br>
> <br>
> layout = QVBoxLayout(self)<br>
> layout.setContentsMargins(0, 0, 0, 0)<br>
> layout.setSpacing(0)<br>
> self.setLayout(layout)<br>
> <br>
> # Add widgets<br>
> widgets = [<br>
> ("red", "Red"),<br>
> ("green", "Green"),<br>
> ("blue", "Blue"),<br>
> ("violet", "Violet"),<br>
> ("black", "Black"),<br>
> ("orange", "Orange"),<br>
> ("olive", "Olive"),<br>
> ("turquoise", "Turquoise"),<br>
> ("white", "White"),<br>
> ]<br>
> for color, title in widgets:<br>
> new_widget = QWidget()<br>
> new_widget.setStyleSheet(f"background: {color};")<br>
> layout.addWidget(new_widget)<br>
> <br>
> # Add a re-arrange button<br>
> new_button = QPushButton("MOVE WIDGET IN LAYOUT")<br>
> new_button.clicked.connect(self.move_widget)<br>
> layout.addWidget(new_button)<br>
> <br>
> def move_widget(self):<br>
> item = self.layout().takeAt(2)<br>
> self.layout().insertItem(4, item)<br>
> <br>
> def main():<br>
> app = QApplication(sys.argv)<br>
> window = TestWindow()<br>
> window.show()<br>
> sys.exit(app.exec())<br>
> <br>
> if __name__ == "__main__":<br>
> main()<br>
> <br>
> Is this bug, or am I doing something wrong?<br>
> <br>
> Regards,<br>
> Matic<br>
<br>
It's a bug - also in PyQt5.<br>
<br>
Thanks,<br>
Phil<br>
</blockquote></div>