[PyKDE] setText of all LineEdits with button click

Bill Burns billburns at pennswoods.net
Sat Sep 25 16:46:54 BST 2004


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......

Thanks,

Bill

The original code again:

!/usr/bin/env python

import os
import sys

from qt import *

class MyLineEdit(QLineEdit): 
    
    def __init__(self, parent):
        QLineEdit.__init__(self, parent)
        self.setText("hello")
  
    def set(self, txt):
        #print txt
        self.setText(txt)
    
    def clearIt(self):
        self.clear()
        
class MainWindow(QMainWindow):

    def __init__(self):
        QMainWindow.__init__(self)
                
        self.grid=QGrid(2, self)
        self.grid.setFrameShape(QFrame.StyledPanel)
        self.setCentralWidget(self.grid)

        self.le0=MyLineEdit(self.grid)
        self.le1=MyLineEdit(self.grid)
        self.le2=MyLineEdit(self.grid)
        self.le3=MyLineEdit(self.grid)      
     
        self.bn1=QPushButton("Set Text", self.grid)
        self.connect(self.bn1, SIGNAL("clicked()"), self.setLineEdit)   
        
    def setLineEdit(self):
        #MyLineEdit(self).set("hi")
        self.le0.clearIt()
        #self.le0.set("hi")
        #self.le1.set("hi")
	#self.le2.set("hi")
	#self.le3.set("hi")
 
def main(args):
    app=QApplication(args)
    win=MainWindow()
    win.show()
    app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()"))
    app.exec_loop()
  
if __name__=="__main__":
    main(sys.argv)
          




More information about the PyQt mailing list