[PyQt] GUI documenting

Andreas Pakulat apaku at gmx.de
Fri Jan 22 18:29:49 GMT 2010


On 22.01.10 17:34:48, FT2 wrote:
> I'm hoping to document the GUI widget instances currently in use in an
> application. Ideally I'd like a function that returns (widget,
> parent), (widget, parent)...
> 
> The aim is to create a documentor for the GUI setup as it exists at a
> given time. The main window will have a function that when triggered,
> creates a text file documenting the whole GUI setup at that moment.
> 
> 
> QDIALOG 1 AND ITS PROPERTIES
>   |
>   | ----- QTABWIDGET 1 AND ITS PROPERTIES
>   |                  |
>   |                  | ----- QWIDGET 1 AND ITS PROPERTIES
>   |                  |                            |
>   |                  |                            | ----- QCHECKBOX 1
> AND ITS PROPERTIES
>   |                  |                            |
>   |                  |                            | ----- QPUSHBUTTON
> 1 AND ITS PROPERTIES
>   |                  |
>   |                  | ----- QWIDGET 2 AND ITS PROPERTIES
>   |                                               |
>   |                                               | ----- QLISTWIDGET
> 1 AND ITS PROPERTIES
>   |
>   | ----- QPUSHBUTTON 2 AND ITS PROPERTIES
>   |
> etc
> 
> 
> Once a list of widgets exists, identifying the type and any properties
> I'm interested in for each is fairly easy.
> 
> Does anyone have sample code how to generate a basic list of "created
> widgets" in the first place? I can't find an example of this. In
> principle it just needs to identify what objects have been created and
> for each, its parent object. Presumably this needs basic knowledge of
> the classes that hold information on objects created in the GUI, but
> I'm not clear what those are or what a snippet for this would look
> like.

You'll need the top-most parent widget, which should be obtainable using
QApplication::topLevelWidgets(). With a QWidget instance you can:

a) walk over all its children objects using QObject::children()
b) ask it for its metaObject() to retrieve the className() from that
c) use the metaobject to retrieve any property values

Andreas

-- 
Go to a movie tonight.  Darkness becomes you.


More information about the PyQt mailing list