[PyQt] Small doc fix
Elvis Stansvik
elvstone at gmail.com
Mon May 30 12:47:20 BST 2016
2016-05-08 17:54 GMT+02:00 Elvis Stansvik <elvstone at gmail.com>:
> 2016-05-08 17:44 GMT+02:00 Elvis Stansvik <elvstone at 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
More information about the PyQt
mailing list