Details
-
Task
-
Resolution: Unresolved
-
P4: Low
-
None
Description
Writing types in C++, it is possible to do interesting things with property setters – for example, clamping values to a range. This is difficult to do from QML – we can't detect value changes until after the fact, and changing a value may remove a binding.
It isn't 100% clear how widely this should be encouraged – for example the existing visible property has led to issues because the value you set and the value you get are not identical (you set local visibility and get inherited visibility). Write interception might lead to similar confusion if not used carefully.
Idea 1:
WriteInterceptor on x { id: interceptor setter: function(newValue) { return Math.max(maxValue, Math.min(minValue, newValue)) } }
Pros: Basic implementation very easy
Cons: Doesn't play nice with Behavior (only one will be called). Requires a QObject for each property that needs interception.
Idea 2:
function[interceptor:x] setX(newValue) { x = Math.max(maxValue, Math.min(minValue, newValue)) }
Attachments
Issue Links
- depends on
-
QTBUG-106094 All Pointer Handlers need to use metaproperties on target() rather than calling setters directly
- Reported
- is required for
-
QTBUG-100636 take BoundaryRule out of Labs to be supported API
- Reported
Gerrit Reviews
For Gerrit Dashboard: QTBUG-59761 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
429865,6 | PinchHandler: don't bypass property interceptors like BoundaryRule | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |