[solved]How do I detect if a rect's members are changed?
-
When I have a rect property, is there an event that is fired the members of the rect are changed? I tried using onMyRectChanged, but that seems to only fire when I assign a different rect to the not when I change the members of the rect.
@Item {
property rect myRect: "0,0,1x1"
onMyRectChanged: {
//this only happens when myRect is reassigned
//not if I do myRect.x = 10
console.log("rect reassigned");
}
}@ -
No there is no catch-all signal for any property. You get notifications for individual properties, so you will have to add print statements to "onXChanged", "onWidthChanged" etc individually by using for instance a Connections element:
@
Connections {
target: myRect
onWidthChanged: print("foo)"
}
@ -
Have you confirmed that this actually works?
I get this error:
@Unable to assign QRectF to QObject*@EDIT:
This is kind of embarrassing... So it seems I simplified my code too much before asking the question. I am exposing a C++ class to QML and I forgot to emit the NOTIFY signal :P. Anyway, now the handler is called whenever I change the attributes of the QRectF. Probably since setMyRect is the only mutating function on my c++ class?Thanks, anyway, it was useful to learn about the connections component.
-
[quote author="bobbaluba" date="1394098502"]Have you confirmed that this actually works?
I get this error:
@Unable to assign QRectF to QObject*@
[/quote]
seebq. individually by using for instance a Connections element
I might be wrong but you should be able to access the notifications directly by:
@Item {
property rect myRect: "0,0,1x1"
onWidthChanged: print("foo")
onXChanged: print("bar")
}@ -
onek24 that will just give you notifications when the dimensions of the Item itself changes. Item has properties called width, height, x, y.
-
[quote author="bobbaluba" date="1394100498"]onek24 that will just give you notifications when the dimensions of the Item itself changes. Item has properties called width, height, x, y.[/quote]
Yes that is right, my answer was based on the answer of Jens who also used the notification onWidthChanged. I just wanted to provide you a way without the Connector.