Is there a way to create an "actual" Qt property in PyQt?
Dennis Jensen
djensen at pgcontrols.com
Mon Oct 19 13:58:37 BST 2020
I am not sure if I am understanding this question correctly but you seem
to asking how to make a Class Property that you can access like a property
@property
def Item(self):
return self.InternalRef
@Item.setter
def Item(self, Value)
self.InternalRef = ValueThat works and allows you to reference the variable like it was a normal
class property? Further this is fairly well documented which is why I do
not understand what you are attempting to ask with this question. Could
you please clarify perhaps using an example of what you are driving at.
That works and allows you to reference the variable like it was a normal
class property? Further this is fairly well documented which is why I do
not understand the what you are attempting to ask with this question.
On 10/18/2020 8:22 PM, Maurizio Berti wrote:
> We all know that we can create custom QObject properties using the
> `pyqtProperty` function/decorator.
>
> 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?
>
>
> Thanks,
> Maurizio
> --
> È difficile avere una convinzione precisa quando si parla delle
> ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20201019/85172844/attachment.htm>
More information about the PyQt
mailing list