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