Link two object attributes to each other
Solved
QML and Qt Quick
-
I'm new to QT and have a question about linking two attributes to eachother.
I want to be able to alter one which should change the other.example:
TextField{ id:textBox text:slideBox.x validator: IntValidator{ top: 255 bottom: 0 } maximumLength: 3 } Rectangle{ id:slideBox width: 10 height: 15 anchors.fill: parent border.width: 1 x : textBox.text MouseArea { anchors.fill: parent drag.target: parent drag.threshold: 0 drag.maximumX: 400 drag.minimumX: 30 } }
Here "slideBox.x" is changed by the text field and "TextField.text" is changed by dragging the box. I know that this creates a nasty loop but I hope you get the idea of what I want to do. Is this possible to do in a good way?
-
TextField{ id:textBox text: slideBox.x validator: IntValidator{ top: 255 bottom: 0 } maximumLength: 3 // onEditingFinished or onTextChanged or onAccepted( choose which fits better ) onEditingFinished: slidebox.x = parseInt(text) } Rectangle{ id:slideBox width: 10 height: 15 anchors.fill: parent border.width: 1 //x : textBox.text MouseArea { anchors.fill: parent drag.target: parent drag.threshold: 0 drag.maximumX: 400 drag.minimumX: 30 } }