[PyKDE] setText of all LineEdits with button click
Bill Burns
billburns at pennswoods.net
Sat Sep 25 18:01:29 BST 2004
Torsten wrote:
> Try something like this (solution 1):
> <code>
> class MyLineEdit(QLineEdit):
> ~ # keeps track of all instances of MyLineEdit,
> ~ # but is buggy if instances are removed
> ~ allinstances = []
> ~ def __init__(self, parent):
> ~ self.allinstances.append(self)
> ~ QLineEdit.__init__(self, parent)
> ~ self.setText("hello")
>
> ~ def set(self, txt):
> ~ self.setText(txt)
>
> ~ def setAll(cls, x):
> ~ for le in cls.allinstances:
> ~ le.set(x)
>
> ~ setAll=classmethod(setAll)
> </code>
>
> and then
> <code>
> def setLineEdit(self):
> MyLineEdit.setAll("hi")
> </code>
>
>
> solution 2:
> <code>
> def setLineEdit(self):
> ~ for name in self.__dict__:
> ~ w = getattr(self, name)
> ~ if isinstance(w, MyLineEdit):
> ~ w.set("hi")
> </code>
>
> There are certainly some more solutions, maybe this helps you finding the
> best one.
>
> greetings
>
> Torsten
Torsten,
Thank you very much! I tried your solution 2 and it works great. I will also
take a look at solution 1.
Thank you Torsten and thank you Michael for your help!!
Bill
More information about the PyQt
mailing list