QLayout error?
RedHuli
redhuli.comments at gmail.com
Mon Oct 10 05:42:30 BST 2022
Hi Matic,
Does changing your move_widget function to the following have the desired
results you want?
def move_widget(self):
widget = self.layout().itemAt(2).widget()
self.layout().removeWidget(widget)
self.layout().insertWidget(4, widget)
Best,
Joshua Willman
On Sun, Oct 9, 2022 at 6:48 PM Phil Thompson <phil at riverbankcomputing.com>
wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20221009/c1030fef/attachment-0001.htm>
More information about the PyQt
mailing list