Is there a way to create an "actual" Qt property in PyQt?
maurizio.berti at gmail.com
Mon Oct 19 02:22:13 BST 2020
We all know that we can create custom QObject properties using the
As far as I know, though, there is a small drawback: those properties do
not behave "exactly" like other QObject properties: the small (but somehow
code-wise significant) difference is that PyQt created properties are
accessible as python properties (self.somePyQtProperty) and not like other
Qt properties (self.someQtProperty*()*, note the parentheses).
I know that this might seem trivial, but it's something that has slightly
buggered me for some amount of time, mostly because I often use the QObject
constructor to automatically set properties.
>From the basic code perspective it's not that an issue: I could set a
custom property to _someProperty and then create the related someProperty()
and setSomeProperty(value) functions for "readability" reasons, but since
I'm using some custom made plugins in designer I'd prefer to keep property
names as clean as possible there too.
Obviously, using def someProperty(self): after the property declaration is
not an option, as it would make property access unavailable.
Note that I don't really care for some further lines in the class
definition/constructor; what I'd really prefer is to always have a
consistent way to access properties if they *also are* Qt properties.
So, the question: is there a way or workaround to allow creating a Qt
property on PyQt that is still accessible using the self.property() syntax,
while keeping the property name intact?
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt