2

i've created a image button class from QLabel. Now i wanna add a clicked signal to that. now, what to do?

 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()

i make a button :

  ImageButton2 = PicButton(QPixmap("image/buy.png"),QPixmap("image/buy_Hover.png"))
  ImageButton2.clicked.connect(self.addStuff)  # but this class has not  clicked signal
iraj jelodari
  • 3,118
  • 3
  • 35
  • 45

1 Answers1

4

QLabels have no default clicked signal. If you want to have one, you must add it yourself and emit it on the correct event.

To dectect the event you can:

mata
  • 67,110
  • 10
  • 163
  • 162