Element.qml
Item{
property int step
property int minValue
property int maxValue
property int value //should accept values of form i*step+minValue
}
main.qml
Element{
step:2
minValue:-7
maxValue:7
value:0 //not an acceptable value(2*i-7), should convert to 1 or -1
}
If I set the value, it should convert the value to nearest step*i+minValue,
i.e. 0 to 1 and then emit valueChanged().
I want the valueChanged() signal to be emitted only when its value is step*i+minValue.
As far as I know there is no way to set a property validator. A possible workaround is shown below. Consider for instance a property that accepts only positive numbers. Such a property can be coded as follows:
The same approach can be used in C++, if
Itemis your custom class.