QHBoxLayout移除控件

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)
原文地址:https://www.cnblogs.com/fuqia/p/9191765.html