Remove an Image in QLabel After Button Clicked

只谈情不闲聊 提交于 2020-01-30 08:34:14

问题


I have qlabels that displaying images . I want to delete image if user clicks remove button . I can learn which image clicked

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

but i couldn't use it and connects with button . How can i remove image ?


回答1:


Assuming labels[] has a list of labels ID, I think you can do something like:

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

Then in self.remove_image and since label.clear() (to clear content of label) is a SLOT then, you can connect it to clicked signal directly:

def remove_image(self, label_id):
    QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL("clicked()"), label_id.clear)


来源:https://stackoverflow.com/questions/34520919/remove-an-image-in-qlabel-after-button-clicked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!