[PyQt] can't get findChild to work
Matt Newell
newellm at blur.com
Tue Jun 8 23:48:53 BST 2010
On Tuesday 08 June 2010 15:29:53 Danny Shevitz wrote:
> Howdy,
>
>
>
> Another newbie question here. I am trying to get findChild to work. The
> code I am trying is
>
>
>
> app=QtGui.QApplication.instance()
>
> print app.allWidgets()
>
> mdiArea=app.findChild(QtGui.QMdiArea)
>
> print "in ElicitorPage, mdiArea = ", mdiArea
>
>
>
> As can be seen, I am getting the global application object, then printing
> all of its widgets (it is an MDI application with
>
> a QMdiArea widget as the central widget). Then I try to find the QMdiArea
> widget. I don't believe I need a name in findChild
>
> since the defaults to "" which matches all instances. I also tried with a
> name, and it didn't work for me anyway. In any case, here is the output
>
> of the code:
>
>
>
> [<PyQt4.QtGui.QMenu object at 0x013F4108>, <PyQt4.QtGui.QMenu object at
> 0x013F4078>, .
>
> <PyQt4.QtGui.QMdiArea object at 0x013D1AE0>]
>
> in ElicitorPage, mdiArea = None
>
>
>
> As you can see, there is clearly a QMdiArea widget in app.allWidgets, and
> yet the findChild method doesn't return it.
>
> Can anyone tell me what I am doing wrong?
>
I think the problem is that the top level widgets aren't really children of
the application from a QObject parent<->child standpoint. The way to do this
would be to loop through app.topLevelWidgets() calling findChild on each.
Matt
More information about the PyQt
mailing list