Is there a way to create an "actual" Qt property in PyQt?

Maurizio Berti maurizio.berti at
Fri Nov 6 02:03:55 GMT 2020

> On 22/10/2020 22:12, Ales Erjavec wrote:
> > A while ago I had a similar thought of subverting the property
> > descriptor protocol:

Well, that's very promising, thanks Ales.
At first look it seems to do exactly what I wanted!
Did you do some further testing to ensure its consistency and reliability?

> IMHO, that's not a property.
> > But have not actually used it anywhere. Usually I just
> > use the convention of adding a underscore suffix to the
> > property member i.e.
> >
> > bar_  = pyqtProperty(int, fget=bar, fset=setBar)
> Q_PROPERTY is a way of implementing in C++ something that is a property
> in QML and Qt Designer. It is not a property in C++.
> Python properties are proper properties.

Unfortunately I'm not that good in low-level programming knowledge, but,
while I see your point, I'd say that from a higher-level perspective (which
is what the average python programmer uses) it's not that "big" a
>From my limited perspective and knowledge, I can only assume that an actual
property is similar in behavior and performance to direct member variables
in C++ (as with QStyleOption variables, for example) instead of using a
callable to access a value.
Nonetheless, as stated in my first message, I'd like a more consistent way
to access custom Qt properties just like the existing ones, and the
solution provided by Ales seems the most promising so far, especially for
properties that do not directly affect performance (such as painting, item
view/delegate implementations or complex layout management).

Thank you,
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the PyQt mailing list