QLayout error?

Phil Thompson phil at riverbankcomputing.com
Mon Oct 10 02:47:57 BST 2022


On 09/10/2022 22:57, Matic Kukovec wrote:
> 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

It's a bug - also in PyQt5.

Thanks,
Phil


More information about the PyQt mailing list