[PyKDE] Looping over QLabels
sundance at ierne.eu.org
Tue Mar 23 15:53:00 GMT 2004
I heard GuineaPig said:
> 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....
There is no direct way to do such a thing that I know of.
However, you could easily code yourself a little function that would get
your widget's subwidgets (with the .children() method) and filter out
the non-QLabel ones:
def getChildrenByType(obj, type):
children = obj.children()
isTypeSuitable = lambda child: child.isA(type)
return filter(isTypeSuitable, children)
for child in getChildrenByType(self, "QLabel"):
More information about the PyQt