[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Small doc fix
From:       Elvis Stansvik <elvstone () gmail ! com>
Date:       2016-05-30 11:47:20
Message-ID: CAHms=eZBb5J7Z=oKrgwtifu9qXBdg0_0e03bTsuZGCZJK+OiJw () mail ! gmail ! com
[Download RAW message or body]

2016-05-08 17:54 GMT+02:00 Elvis Stansvik <elvstone@gmail.com>:
> 2016-05-08 17:44 GMT+02:00 Elvis Stansvik <elvstone@gmail.com>:
>> Hi Phil,
>>
>> A small fix for:
>>
>>     http://pyqt.sourceforge.net/Docs/PyQt5/qt_properties.html
>>
>> would be to change:
>>
>>     notify – the optional unbound notify signal. It is ignored by Python
>>
>> to
>>
>>     notify – the optional unbound notify signal. Only needed if you
>> want to use the property in QML property bindings
>>
>> since it seems I must use it if I want to use the property in QML
>> property bindings, e.g:
>>
>> Window {
>>     color: machine.initializing ? "red" : "green"
>>     ...
>> }
>>
>> or else I'll get errors like:
>>
>>     QQmlExpression: Expression
>> file:///home/estan/Projekt/orexplore/dev/src/orexplore.machine/orexplore/hmi/qml/main.qml:15:12
>> depends on non-NOTIFYable properties: Machine::initializing
>
> Correct me if I'm doing something else wrong of course :) The property
> is defined like (only relevant parts shown):
>
> class Machine(QObject):
>
>     initializingChanged = pyqtSignal(bool, arguments=['initializing'])
>
>     def __init__(self, *args, **kwargs):
>         super().__init__(*args, **kwargs)
>
>         self._initializing = False
>
>     @pyqtProperty(bool)
>     def initializing(self):
>         return self._initializing
>
>     @initializing.setter
>     def initializing(self, initializing):
>         if initializing != self._initializing:
>             self._initializing = initializing
>             self.initializingChanged.emit(self._initializing)
>
> and adding notify=initializingChanged to @pyqtProperty fixes the error.
>

I've realized that the same is true for the constant parameter to
pyqtProperty as well. The docs currently says:

    "optionally sets the Qt CONSTANT flag. It is ignored by Python"

But when working with QML, this argument actually has a function: If
you have truly constant properties, this flag can be used to avoid
getting errors about non-NOTIFYable properties when using the
properties in bindings.

Elvis

> Elvis
>
>>
>> Cheers,
>> Elvis
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic