According to PSEP 101[1] a constructor for QObject and derived classes
should be able to set Qt properties through named arguments.
In practical terms to set the Qt property "objectName" to "foobar" one
should do:
obj = QObject(objectName='foobar')
This can be done in a more verbose way:
obj = QObject()
obj.setProperty('objectName', 'foobar')
You can set dynamic properties, i.e. not previously declared on the
QObject derived object:
obj = QObject()
obj.setProperty('myNumber', 123)
If you don't already know which is which from reading the
documentation, QObject.setProperty will return True for existing Qt
properties and False for newly created ones.
Now, the point of this email is to change PSEP 101 to allow the
QObject (and derived types) constructor to accept setting dynamic Qt
properties. PyQt and the current PSEP 101 only provide this for
already existing Qt properties, while QObject.setProperty doesn't, and
I think this an unnecessarily exceptional behaviour.
We had a short discussion on #pyside IRC channel and one point of
prohibiting the setting of dynamic properties using the constructor
would allow the programmer to make mistakes without knowing. Mistakes
such as
obj = QObject(objectname='myName')
This wouldn't set the existing 'objectName' property, instead it would
create the new 'objectname' one. The programmer wouldn't get any
feedback and everything would eventually crash at some point.
Nevertheless, the alternative
obj = QObject()
obj.setProperty('objectname', 'myName')
would result in the same problem, since people rarely check the result
of setProperty.
In summation my opinion is that the constructors should not have
special cases for dynamic Qt properties.
Any thoughts?
[1] http://qt.gitorious.org/pyside/pseps/blobs/master/psep-0101.txt
and the merge request: http://qt.gitorious.org/pyside/pseps/merge_requests/2
--
Marcelo Lira dos Santos
INdT - Instituto Nokia de Tecnologia
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside