2011/1/2 Algis Kabaila <[email protected]>:
> To put it briefly, if it is a good practice to use setObjectName
> on all objects, I would like to know and tell others to do that.

Check out the documentation about the "objectName" property:

http://doc.qt.nokia.com/latest/qobject.html#objectName-prop

It turns out that you can use "findChild" to search for children by name:

http://doc.qt.nokia.com/latest/qobject.html#findChild

So if you only have a reference to your top-level window, you could
get a reference to the child with the specific name using the
findChild method on the top-level window.

My guess would be that for auto-generated code (from .ui files), you
can just leave it in (and maybe take advantage of findChild if you
want to get a specific object), and for code that you write yourself,
you would only set an object name if you want to use findChild later
to get a reference to that object from a higher-level (direct or
indirect parent) widget/object.

This could also be useful if you set the same name on multiple widgets
and then interate over all those widgets with findChildren, e.g. you
have several buttons sprinkled throughout one window, and all "belong"
together somehow. If you name them all "fooButton", you could use "for
button in window.findChildren('fooButton'): ..." to iterate over all
buttons. I haven't used this myself, so maybe there are some other
more obvious use cases for object names :)

HTH.
Thomas
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to