2016-06-01 4 views
0
datainputHbox = QHBoxLayout() 
layout = QVBoxLayout(self) 
layout.addLayout(datainputHbox) 


pagedatainputdeletboxbutton1.clicked.connect(lambda:self.boxdelete(datainputHbox)) 

def boxdelete(self, box): 

이 datainputHbox 양식 레이아웃을 제거하기 위해 boxdelete 연료 소모량을 쓰기 어떻게 PyQt는의 proragm 인에서 레이아웃을 제거합니다. 나는 많은 것을 시도한다. 그러나 모든 위젯을 제거 할 수는 있지만 레이아웃을 제거 할 수는 없습니다.PyQt는 어떻게 레이아웃

+0

허에서 boxdelete 기능을

def deleteItemsOfLayout(layout): if layout is not None: while layout.count(): item = layout.takeAt(0) widget = item.widget() if widget is not None: widget.setParent(None) else: deleteItemsOfLayout(item.layout()) 

함께 글로벌 기능을

충돌을 일으켰습니다. 정말'removeLayout' 함수가 있다고 생각했습니다 ... –

답변

2

해당 QLayoutItem을 가져 와서 제거하여 QLayouts을 제거 할 수 있습니다. 또한 레이아웃에 대한 참조를 저장해야합니다. 그렇지 않으면 나중에 속한 위젯을 알지 못하는 한 나중에 다른 방법으로 액세스 할 수 없습니다. 일반적인 답변으로

datainputHbox = QHBoxLayout() 
self.vlayout = QVBoxLayout(self) 
layout.addLayout(datainputHbox) 
pagedatainputdeletboxbutton1.clicked.connect(lambda: self.boxdelete(datainputHbox)) 

def boxdelete(self, box): 
    for i in range(self.vlayout.count()): 
     layout_item = self.vlayout.itemAt(i) 
     if layout_item.layout() == box: 
      self.vlayout.removeItem(layout_item) 
      return 
0

: taken from here 약간의,하지만 중요한 변화 : 당신은() widget.deleteLater를 호출하지 않아야합니다. 내 경우에는 적어도 이것은 파이썬이 Brendan Abel's 대답

def boxdelete(self, box): 
    for i in range(self.vlayout.count()): 
     layout_item = self.vlayout.itemAt(i) 
     if layout_item.layout() == box: 
      deleteItemsOfLayout(layout_item.layout()) 
      self.vlayout.removeItem(layout_item) 
      break