PDA

View Full Version : Property alias - make visible rectangle in other qml file



bchinfosieeuw
27th August 2016, 22:17
I have looked at the following site, and I am trying to get it working: http://stackoverflow.com/questions/25401248/changing-property-of-element-from-other-qml-file
I did not get it working with this code:


ToClick.qml:


ToChange
{
id:luncherList
}
(in mousearea:)
onClicked:
{
luncherList.callUrl = 'T';
}




ToChange.qml:


visible: false
property alias callUrl: item1.visible
onCallUrlChanged:
{
item1.visible = (callUrl != 'T' ? false : true);
}



What do I have to do to make visible the rectangle of item1 in ToChange.qml on click of ToClick.qml?

anda_skoa
27th August 2016, 23:44
That makes no sense.

ToChange.qml defines "callUrl" as an alias for "visible" of another element, which is a boolean property.
You can't assign 'T' to a boolean.

If ToClick needs to change the visible property of item1 inside ToChange, then just assign the value you need (true or false) to the alias property.
You might want to use a different name then callUrl, since it is a boolean, not an url

Cheers,
_

bchinfosieeuw
28th August 2016, 11:50
Thanks for the explanation. Now I also want to change color of the rectangle of item1 in ToChange.qml on click of ToClick.qml. I tried but how to get it working?

anda_skoa
28th August 2016, 16:39
Assuming "item1" is your rectangle, just make an alias property for its "color" property.

Cheers,
_

bchinfosieeuw
28th August 2016, 21:18
No, item1 is the Item, in which a rectangle is placed called circle. So how do I change the color of this circle from clicking on a rectangle of the other file?

anda_skoa
28th August 2016, 21:57
Give the rectange an id, create an alias property for the rectangle's color using that id.

Cheers,
_

bchinfosieeuw
28th August 2016, 22:58
This is what I have, but it is not changing color of the rectangle called circle:

ToClick.qml:


onClicked:
{
luncherList.colorRef = "blue";
}


ToChange.qml:


property alias colorRef: circle.colorUrl

Rectangle {
id: circle
property color colorUrl
onColorUrlChanged:
{
console.log("hello3");
circle.colorUrl = "blue"
}


Can you tell me what I am doing wrong?

bchinfosieeuw
30th August 2016, 20:42
When the rectangle (id: circle) in Page2 is pressed, its color changes because the State says so. But how can I change the color of the rectangle in Page2 from onPressed in Page1?

Page1.qml:
MouseArea {
id: myma
//...

Page2.qml:


states: State {
name: "resized"; when: mymousearea.pressed
PropertyChanges { target: circle; color: "blue" }
}

anda_skoa
31st August 2016, 10:08
If you have an instance of Page2 inside Page1, then you can set any property of that Page2 instance.

If any such property is the binding of the inner rectangle's color property or an alias to that then you will change that inner rectangle's color.

Cheers,
_

bchinfosieeuw
2nd September 2016, 12:06
When the colorUr is changed from another file, the color of the circle must change. A you can see, the circles are placed on the mouseArea by clicking on it. The console says "hello6", but the color of the circle is not changed. I do not get it working. Please help.




property alias colorUr: myma.colorMy2

Rectangle {
id: circle

MouseArea {
id: myma
anchors.fill: parent
property color colorMy2
onColorMy2Changed:
{
console.log("hello6");
circle.color = "green"
}
}
}

anda_skoa
2nd September 2016, 13:09
I've merged your various duplicated threads since it is pointless to answer the same questions again and again.

Cheers,
_