单击按钮后在QLabel中删除图像

问题描述 投票:0回答:1

我有显示图像的qlabel。如果用户单击“删除”按钮,我想删除图像。我可以了解点击了哪个图像

labels[i].mousePressEvent = functools.partial(self.remove_image, source_label = labels[i] ,source_image = pixmap)

但我无法使用它并与button连接。如何删除图像?

pyqt pyqt5
1个回答
1
投票

假设labels[]具有label的ID列表,我想您可以执行以下操作:

labels[i].mousePressEvent = functools.partial(self.remove_image, source_label = labels[i]) #just pass to self.remove_image the label id

然后在self.remove_image中,并且由于label.clear()(用于清除标签的内容)是SLOT,因此,您可以将其直接连接到clicked信号:

def remove_image(self, label_id):
    QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL("clicked()"), label_id.clear)
© www.soinside.com 2019 - 2024. All rights reserved.