PyQt button click area (Non rectangular area)

I m working on a PySide interface for Maya and i was wondering if its possible to define a NON RECTANGULAR clickable area for a button.
I tried using a QLabel whit a custom subclass to get some QPushbutton behavior (signals, etc;), and finally attach an image to it . i´ts possible to define in that QLabel containing a picture with alpha channel and use that alpha to define the click area for that custom button?

I’d appreciate a lot if you can guide me through how to solve this problem. Thanks in advance.

I’ve tried this… But i´m still have some degree issues and i can’t get rid of the rectangular selectable area… :|:

from PySide import QtCore
from PySide import QtGui 

class QLabelButton(QtGui.QLabel):

    def __init(self, parent):
        QtGui.QLabel.__init__(self, parent)

    def mousePressEvent(self, ev):
        self.emit(QtCore.SIGNAL('clicked()'))

class CustomButton(QtGui.QWidget):
    def __init__(self, parent=None, *args):
        super(CustomButton, self).__init__(parent)
        self.setMinimumSize(300, 350)
        self.setMaximumSize(300, 350)

        picture = __file__.replace('qbtn.py', '') + 'mario.png'
        self.button = QLabelButton(self)
        self.button.setPixmap(QtGui.QPixmap(picture))
        self.button.setScaledContents(True)

        self.connect(self.button, QtCore.SIGNAL('clicked()'), self.onClick)

    def onClick(self):
        print('Button was clicked')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = CustomButton()
    win.show()
    app.exec_()
    sys.exit()


you’ll probably need to override mousePressEvent (or release?) and then do a hit test on the image to see if the point was over the alpha or not, then emit the clicked signal if so

Hey Maxx thanks for your answer.

Here in the estudio we already resolve the issue :). The solution was just to add the the image not just only as a pixmap. You have to added as mask to ! using the Qt setMask function. So the button assume that image as a border definition and only emit signals inside that area.

Here the code if somebody have the same trouble.

from PySide import QtCore
from PySide import QtGui 

class QLabelButton(QtGui.QLabel):

    def __init(self, parent):
        QtGui.QLabel.__init__(self, parent)

    def mousePressEvent(self, ev):
        self.emit(QtCore.SIGNAL('clicked()'))

class CustomButton(QtGui.QWidget):
    def __init__(self, parent=None, *args):
        super(CustomButton, self).__init__(parent)
        self.setMinimumSize(300, 350)
        self.setMaximumSize(300, 350)

        picture = __file__.replace('qbtn.py', '') + 'mario.png'
        self.button = QLabelButton(self)
        self.button.setPixmap(QtGui.QPixmap(picture))
        self.button.setMask(self.pixmap.mask()) #<----- New line of code using setMaks and passing the image itself as a mask :)
        self.button.setScaledContents(True)

        self.connect(self.button, QtCore.SIGNAL('clicked()'), self.onClick)

    def onClick(self):
        print('Button was clicked')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = CustomButton()
    win.show()
    app.exec_()
    sys.exit()