我从 QLabel 创建了一个图像按钮类。现在我想添加一个点击信号。现在,该怎么办?
class PicButton(QLabel):
def __init__(self,pixmap1,pixmap2,parent=None):
QLabel.__init__(self, parent)
self.pic = pixmap1
imageSize = self.pic.size()
imageSize.setWidth(imageSize.width()*.7)
imageSize.setHeight(imageSize.height()*.7)
self.pic = self.pic.scaled(imageSize,Qt.KeepAspectRatioByExpanding)
self.pic2 = pixmap2
imageSize2 = self.pic2.size()
imageSize2.setWidth(imageSize2.width()*.7)
imageSize2.setHeight(imageSize2.height()*.7)
self.pic2 = self.pic2.scaled(imageSize2,Qt.KeepAspectRatioByExpanding)
def enterEvent(self, event):
self.setPixmap(self.pic2)
event.accept()
def leaveEvent(self, event):
""" When the mouse leave this widget, destroy it. """
self.setPixmap(self.pic)
self.destroy()
我做一个按钮:
ImageButton2 = PicButton(QPixmap("image/buy.png"),QPixmap("image/buy_Hover.png"))
ImageButton2.clicked.connect(self.addStuff) # but this class has not clicked signal