QLayout error?

Matic Kukovec kukovecmatic at hotmail.com
Sun Oct 9 22:57:00 BST 2022


Hi,

My specs: Windows 10 x64, Python3.10 x64, PyQt6.3.1

When clicking the button in the below example, a crash without a traceback occurs:
import sys
from PyQt6.QtCore import *
from PyQt6.QtGui import *
from PyQt6.QtWidgets import *

class TestWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setFixedSize(640, 480)

        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.setLayout(layout)

        # Add widgets
        widgets = [
            ("red", "Red"),
            ("green", "Green"),
            ("blue", "Blue"),
            ("violet", "Violet"),
            ("black", "Black"),
            ("orange", "Orange"),
            ("olive", "Olive"),
            ("turquoise", "Turquoise"),
            ("white", "White"),
        ]
        for color, title in widgets:
            new_widget = QWidget()
            new_widget.setStyleSheet(f"background: {color};")
            layout.addWidget(new_widget)

        # Add a re-arrange button
        new_button = QPushButton("MOVE WIDGET IN LAYOUT")
        new_button.clicked.connect(self.move_widget)
        layout.addWidget(new_button)

    def move_widget(self):
        item = self.layout().takeAt(2)
        self.layout().insertItem(4, item)

def main():
    app = QApplication(sys.argv)
    window = TestWindow()
    window.show()
    sys.exit(app.exec())

if __name__ == "__main__":
    main()

Is this bug, or am I doing something wrong?

Regards,
Matic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20221009/c55fd9c3/attachment.htm>


More information about the PyQt mailing list