PyQt - QLabel inheriting
Posted
by Ockonal
on Stack Overflow
See other posts from Stack Overflow
or by Ockonal
Published on 2009-06-07T19:38:54Z
Indexed on
2010/05/06
6:28 UTC
Read the original article
Hit count: 243
Hello, i wanna inherit QLabel to add there click event processing. I'm trying this code:
class NewLabel(QtGui.QLabel):
def __init__(self, parent):
QtGui.QLabel.__init__(self, parent)
def clickEvent(self, event):
print 'Label clicked!'
But after clicking I have no line 'Label clicked!'
EDIT:
Okay, now I'm using not 'clickEvent' but 'mousePressEvent'. And I still have a question. How can i know what exactly label was clicked? For example, i have 2 edit box and 2 labels. Labels content are pixmaps. So there aren't any text in labels, so i can't discern difference between labels. How can i do that?
EDIT2: I made this code:
class NewLabel(QtGui.QLabel):
def __init__(self, firstLabel):
QtGui.QLabel.__init__(self, firstLabel)
def mousePressEvent(self, event):
print 'Clicked'
#myLabel = self.sender() # None =)
self.emit(QtCore.SIGNAL('clicked()'), "Label pressed")
In another class:
self.FirstLang = NewLabel(Form)
QtCore.QObject.connect(self.FirstLang, QtCore.SIGNAL('clicked()'), self.labelPressed)
Slot in the same class:
def labelPressed(self):
print 'in labelPressed'
print self.sender()
But there isn't sender object in self. What i did wrong?
© Stack Overflow or respective owner