[PyKDE] Looping over QLabels
    Greg Fortune 
    lists at gregfortune.com
       
    Tue Mar 23 17:10:00 GMT 2004
    
    
  
On Tuesday 23 March 2004 07:20 am, Toby Dickenson wrote:
> On Tuesday 23 March 2004 14:10, GuineaPig wrote:
> > Hello,
> >
> > In my application I have a QDialog with a lot of QLabels.  From time to
> > time these labels need to be cleared (text set to '').  Is there a way
> > to iterate over the labels ?
> > I'm looking for something like this:
> >
> > for QLabel in self....
> >   QLabel.setText('')
> >
> > Instead of having to do this:
> >
> > QLabel1.setText('')
> > QLabel2.setText('')
> > QLabel3.setText('')
>
> for label in (self.label1, self.label2, self.label3):
>     label.setText('')
or this ugly hack ;o)
i=1
while(i<the_highest_num_label):
	if(self.hasattr('label' + str(i))):
		label = self.getattr('label' + str(i))
		label.setText('')
The node traversal is probably a better solution though..  If you do the 
traversal inside __init__ on your dialog and store the resultant set of 
labels, you would only have to traverse the nodes once and you don't have to 
hard code the list of labels into every dialog.  
Greg Fortune
Fortune Solutions
    
    
More information about the PyQt
mailing list