How to pass variables between Rectangles?
-
How do I pass a variable from rectangle bottom to rectangle left. For e.g. the code below, I like to pass the bottomMouseY variable of rectangle bottom to rectangle left
Is it related to signals and slots? But I can't find any info about signals and slots for Qt quick
@
Rectangle {
id: bottomMouseArea { id: bottomMouseAreaBorderTop hoverEnabled: true property int bottomMouseY onPressed: { bottomMouseY = mouseY } onPositionChanged: { // pass bottomMouseY to rectagle left } }
}
Rectangle {
id: left}
@ -
Do you mean next:
@Rectangle {
id: left
property alias bottomMouseY1 : bottomMouseAreaBorderTop.bottomMouseY
}@ -
- Declare a property on bottom, mouseY, say
- In the onPressed: signal handler, set the bottom.mouseY property
- In left, declare a property, bottomMouseY, say and bind it to bottom.mouseY
Something like this (not tested):
@
Rectangle {
id: bottom
property int mouseY: -1MouseArea { id: bottomMouseAreaBorderTop hoverEnabled: true onPressed: { bottom.mouseY = mouse.y } onPositionChanged: { bottom.mouseY = mouse.y } }
}
Rectangle {
id: left
bottomMouseY: bottom.mouseY
}
@ -
Thank you Alexander and ZapB for your help, it works!
ZapB, the second rectangle should be
@
Rectangle {
id: left
property int bottomMouseY: bottom.mouseY
}
@for it to work
-
Yeah, I did say "not tested". Thanks for pointing out my (ahem) deliberate mistake ;-)