[PyQt] signal propagating
Matt Newell
newellm at blur.com
Wed Sep 29 19:37:15 BST 2010
On Tuesday 28 September 2010 14:00:13 Eric Frederich wrote:
> Hello,
>
> Here's a stripped down example of my problem.
> I have a group of widgets that I keep together with a class called
> MyWidgetGroup.
> It holds a line edit and a label which together have a meaning (getMeaning)
> but by themselves mean nothing.
>
> I need to make connections to a method so it'll get called whenever the
> widget's text changes but I don't want the reference to the line edit, I
> want the reference to the widget group (so I can getMeaning on it).
>
> To do this I wound up creating a dummy method that just propagates the
> signal so that it comes from the widget group instead of just the line
> edit. I have a bad feeling about this. There must be a better way to do
> this right?
> Can this be accomplished by connecting signals to signals?
>
Yes. Define your signal inside your class, then connect the line edit's signal
to it.
Here's a complete working example.
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyWidgetGroup(QWidget):
theValueChanged = pyqtSignal()
def __init__(self, parent=None):
super(MyWidgetGroup, self).__init__(parent)
self.myLabel = QLabel(self)
self.myEdit = QLineEdit(self)
self.myEdit.textChanged.connect( self.theValueChanged )
self.theValueChanged.connect( self.valueChangedSlot )
def valueChangedSlot(self):
print "It works"
app = QApplication([])
widget = MyWidgetGroup()
widget.show()
app.exec_()
Matt
PS Next time it would be nice if your example was runnable.
More information about the PyQt
mailing list