Search code examples
pythonqtpyqtpyqt4

how code a Image button in PyQt?


Im trying to do simple audio player, but I want use a image(icon) as a pushbutton.


Solution

  • I've seen that a lot of people have this problem and decided to write a proper example on how to fix it. You can find it here: An example on how to make QLabel clickable The solution in my post solves the problem by extending QLabel so that it emits the clicked() signal. The extended QLabel looks something like this:

    class ExtendedQLabel(QLabel):
    
        def __init__(self, parent):
            QLabel.__init__(self, parent)
    
        def mouseReleaseEvent(self, ev):
            self.emit(SIGNAL('clicked()'))
    

    I hope this helps!