Solved Using custom types
-
Hi
I have this type defined (not my own work - found it in this forumimport QtQuick 2.10 import Launcher 1.0 Rectangle { property bool commonBorder : true property int lBorderwidth : 1 property int rBorderwidth : 1 property int tBorderwidth : 1 property int bBorderwidth : 1 property int commonBorderWidth : 1 z : -1 property string borderColor : "white" color: borderColor anchors { left: parent.left right: parent.right top: parent.top bottom: parent.bottom topMargin : commonBorder ? -commonBorderWidth : -tBorderwidth bottomMargin : commonBorder ? -commonBorderWidth : -bBorderwidth leftMargin : commonBorder ? -commonBorderWidth : -lBorderwidth rightMargin : commonBorder ? -commonBorderWidth : -rBorderwidth } }
I have used this as follows
Rectangle { anchors.centerIn: parent width : 100 height: 100 color: "yellow" CustomBorder { commonBorder: false lBorderwidth: 0 rBorderwidth: 0 tBorderwidth: 10 bBorderwidth: 10 borderColor: "blue" } MouseArea { id: mouseArea anchors.fill: parent } }
As you can see I have a mouse area that I have connected -
Connections { target: mouseArea onClicked: { } }
Now to the question -
How can I set the properties of the CustomBorder inside the onClicked handler?
Thanks -
hi @GrahamLa ,
I would say, the same way as with normal/standard items.
You give your CustomBorder-item a specificid:
and you reference that in the onClick function.for example:
CustomBorder { id:myBorder commonBorder: false lBorderwidth: 0 rBorderwidth: 0 tBorderwidth: 10 bBorderwidth: 10 borderColor: "blue" } MouseArea { id: mouseArea anchors.fill: parent onClicked:{ myBorder.lBorderwidth: 10 myBorder.rBorderwidth: 10 myBorder.tBorderwidth: 0 myBorder.bBorderwidth: 0 myBorder.borderColor: "red" } }
-
In addition to what @J-Hilk said, please note that when you have type, you need to create the object of that type. This you have done using the CustomBorder type. You need to identify this object with identity property. Using this identify property you can set the property of an object.