我有显示图像的qlabel。如果用户单击“删除”按钮,我想删除图像。我可以了解点击了哪个图像
labels[i].mousePressEvent = functools.partial(self.remove_image, source_label = labels[i] ,source_image = pixmap)
但我无法使用它并与button连接。如何删除图像?
假设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)