[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] events / signals
From:       fpp <fpp.gsp () gmail ! com>
Date:       2010-08-26 17:38:32
Message-ID: AANLkTiny8-z=dgS9UCdOhu-9cnN+Voy7svEYCBo2sbvp () mail ! gmail ! com
[Download RAW message or body]

On Wed, Aug 25, 2010 at 10:43 PM, Eric Frederich
<eric.frederich@gmail.com> wrote:
> If I find myself subclassing a widget just to get something to happen on an
> event am I doing something wrong?
> Is there another way to accomplish this?
> Is there a way to use an event like a signal in a self.connect?
> For example... If I want so do something when a label is clicked I have done
> the following and then just connect to the signal I emmit.
> class ClickableLabel(QLabel):
>     def __init__(self, *args, **kwargs):
>         super(ClickableLabel, self).__init__(*args, **kwargs)
>     def mousePressEvent(self, event):
>         self.emit(SIGNAL("clicked"))

I guess it depends... If you have only one such label in your app, you
don't need a subclass or even a signal.

You can just assign your own function to the method of a QLabel instance, as in:

self.myClickableQLabel.mousePressEvent = self.on_QLabel_clicked

then define what happens there:

def on_QLabel_clicked(self, event):
   print "Aha!"

Then again, if you need several such labels, creating a subclass
avoids code duplication.
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic