[PyKDE] setText of all LineEdits with button click

Torsten Marek shlomme at gmx.net
Sat Sep 25 17:04:26 BST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Burns wrote:
| On Saturday 25 September 2004 10:28 am, Michael Andrews wrote:
|
|>I'm a little rusty, but try this:
|>
|>    def setLineEdit(self):
|>        self.le0.set("hi")
|>        self.le1.set("hi")
|>        self.le2.set("hi")
|>        self.le3.set("hi")
|>
|
|
| Michael,
| Thank you this works and it gets me in the right direction! I appreciate the
| reply.
|
| Can you tell me how to make the class method act upon all instances of
| MyLineEdit without specifically calling out le0, le1, le2, etc.
| individually??
|
| The actual program that I'm working on has twenty-four LineEdits and my
| ultimate goal in posting my original question was to understand how to create
| a method that acts upon all instances of MyLineEdit. Of course I don't know
| if this is the right thing to do or not, I just learning myself......
|
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 Marek <shlomme at gmx.net>
ID: A244C858 -- FP: 1902 0002 5DFC 856B F146  894C 7CC5 451E A244 C858
Keyserver: subkeys.pgp.net

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBVZcJfMVFHqJEyFgRAtpBAJ9JVEUB5BFs5fY43WthVO/lTWpZ2gCgvpcx
B77xHwmnHh9d6WzQI8BFo3s=
=+Y+V
-----END PGP SIGNATURE-----




More information about the PyQt mailing list