我尝试用self.vbox.takeAt(0)
清除QVBoxLayout,但之前的vbox阻塞了QWidget并且不会消失。新的出现在旧的之上。
整个代码https://pastebin.com/n43BH1R0
class Worker(QObject):
CLEAR_VBOX = pyqtSignal()
intReady = pyqtSignal(int)
@pyqtSlot()
def procCounter(self):
for i in range(1, 100):
self.CLEAR_VBOX.emit()
self.intReady.emit(i)
time.sleep(1)
class Form(QWidget):
..
..
def initUI(self):
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
self.setGeometry(333, 333, 222, 222)
self.show()
def clearvbox(self):
while self.vbox.count():
# ~ # break
self.vbox.takeAt(0)
def onIntReady(self, i):
hbox = QHBoxLayout()
for ii in range(i):
ll = QLabel(str(random.randint(1,9)))
hbox.addWidget(ll)
self.vbox.addLayout(hbox)
答案 0 :(得分:0)
def clearvbox(self, L = False):
if not L:
L = self.vbox
if L is not None:
while L.count():
item = L.takeAt(0)
widget = item.widget()
if widget is not None:
widget.deleteLater()
else:
self.clearvbox(item.layout())