[PyQt] Qt Property System
Phil Thompson
phil at riverbankcomputing.com
Thu Jun 15 16:47:03 BST 2017
On 15 Jun 2017, at 4:30 pm, Christopher Probst <christop.probst at gmail.com> wrote:
>
> Hi,
>
> I am starting to feel a lot of love for PyQt. I am inquiring about how the Qt Property system translates into PyQt
>
> The documentation states:
> "PyQt5 does not support the setting and getting of Qt properties as if they were normal instance attributes. This is because the name of a property often conflicts with the name of the property’s getter method."
>
> Does this mean I can't write label.setProperty("text" , "HelloWorld")? I am not exactly sure what this means.
>
> I have tried this for instance and it works great:
>
> for i in range(0, propertyCount):
> metaProperty = metaObject.property(i)
> typeName = metaProperty.typeName()
> propertyName = metaProperty.name()
> value = object.property(metaProperty.name())
> print("propertyName: " + propertyName + ", value: " + str(value) + ", type: " + typeName)
>
> Do we use the Qt Property system in PyQt?
You can use Qt properties from Python as you can from C++ as your code above shows.
The documentation is trying to point out that you can't use Qt properties as it they were Python properties. In other words you cannot do...
label.text = "HelloWorld"
However you can use pyqtProperty to define properties that behave as both Python and Qt properties at the same time.
Phil
More information about the PyQt
mailing list