Python Forum
[PyQt] remove widgets of a layout
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] remove widgets of a layout
#2
I think messing with layouts to change a view is a bad idea. If I want to change how parts of a window looks based on some selection or mode I would use a QStackedWidget.

I have a question about your code:
def clearlayout(layout):
    for i in reversed(range(layout.count())):
        print(layout.itemAt(i))
        layout.itemAt(i).setParent(None)  <- Why 1
        layout.removeItem(layout.itemAt(i))
        layout.itemAt(i).show()   <- Why 2
Why 1:
Why are you setting the parent to None? A widget with no parent becomes a top level window. When you run this don't you get a bunch of little windows popping up on the desktop?

Why 2: You just removed layoutItem[i]. It is gone.
Reply


Messages In This Thread
remove widgets of a layout - by catlessness - Apr-02-2020, 05:40 PM
RE: remove widgets of a layout - by deanhystad - Apr-02-2020, 07:20 PM
RE: remove widgets of a layout - by catlessness - Apr-02-2020, 07:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug [PyQt] Dinamically adding widgets to layout [PySide6] carecavoador 2 1,370 Jun-19-2023, 12:57 PM
Last Post: carecavoador
  [Tkinter] Frames layout adding widgets klatlap 7 1,980 Jan-29-2022, 10:17 PM
Last Post: klatlap
  pyqt5 layout Nickd12 8 3,403 Jan-18-2021, 09:09 AM
Last Post: Axel_Erfurt
  Python GUI layout off between different OS shift838 5 3,622 Jan-02-2019, 02:53 AM
Last Post: shift838
  clear all widgets at same time (not delete/remove) shift838 0 2,716 Dec-17-2018, 11:55 PM
Last Post: shift838
  [Tkinter] grid layout neech 8 17,495 Oct-14-2016, 07:06 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020