Personally I'm not too fond of "hidden" magic in setters/getters. So
I'd just make it explicit, something like:
Foo {
id: foo
property bool checked: false
property bool _someCondition: (a< b)
function setChecked(onOff) {
if (_someCondition)
foo.checked = onOff
}
}
MouseArea {
onClicked: foo.setChecked(!foo.checked)
}
On 05/31/2012 07:21 PM, Johannes Zellner wrote:
> Hi,
>
> maybe the question was already raised and I just missed that. I did not find
> anything so far.
>
> Is there a way in QML to create custom setters or getters to properties?
>
> The issue I am facing is a, to be able to control the setting of a custom
> property, based on the component internal state.
> The snippet is not complete nor working, but should show the issue:
>
> Foo {
> id: foo
> property bool checked: false
> property bool _someCondition: (a< b)
> }
>
> Rectangle {
> color: foo.checked ? "green" : "red"
> }
>
> MouseArea {
> onClicked: foo.checked = !foo.checked
> }
>
> So clicking on the MouseArea toggles the foo.checked, but the actual
> foo.checked should be only changed if foo._someCondition is true. So the
> Rectangle's color binding should only be evaluated in case the foo.checked
> really changes. Resetting the property after doing some onCheckedChanged is
> not what I want.
> I only found a clean solution with creating a custom setter here, which is of
> course possible when creating a custom c++ class for Foo{}.
>
> Would be nice to avoid this, any ideas? Maybe there is a plain simple solution
> and my QML knowledge is just too limited :-)
>
> Thanks,
> Johannes
> _______________________________________________
> Qt-qml mailing list
> [email protected]
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml