1. 程式人生 > >QHBoxLayout移除控件

QHBoxLayout移除控件

not n) nis children pan nbsp DC item button

def clear_layout(widget, layout):
        buttons = widget.findChildren(QtGui.QPushButton)
        while layout.itemAt(0) is not None:
            layout.removeItem(layout.itemAt(0))
        for i in buttons:
            i.setParent(None)

i.setParent(None)是必須的,如果只removeItem,則控件並不會消失

def clear_btn(widget, layout, object):
        
for i in object: finish_btn = widget.findChild(QtGui.QPushButton, i) layout.removeWidget(finish_btn) finish_btn.setParent(None)

QHBoxLayout移除控件