Solved property binding just for initial value
-
Hi,
in my program all values are stored in a big config.qml
If i want to use colors, gradients etc. I create a variable and bind it to the master-value in my config.qml.
Now i have the problem if i want to edit some values like
value: value * 3
my "master-value gets the change too and not just the value in the component.I tried with readonly property but i get the problem that i can't make readonly Gradients
Any idea to solve it?
-
@petzold So how about local property? This will initially be binded to global property in individial components which can then me modified later.
-
That is the way i'm looking for. but how to do?
property Gradient offGradient: Config.offlineGradient
That is the way i did. I have different gradients for different states.
Later i modify the actual gradient withQt.darker Qt.lighter
for some mouse-actions (hover, clicked etc.)
So at the moment i have the problem that my globalConfig.offlineGradient get the change and not just offGradient.
-
@petzold I was saying something like this:
Window { width: 200 height: 200 visible: true property int globalProperty: 30 Item { id: item property int localProperty: globalProperty anchors.fill: parent Text { id: txt anchors.centerIn: parent text: item.localProperty MouseArea { anchors.fill: parent onClicked: { item.localProperty = 60 console.log(globalProperty) } } } } }
Initially localproperty holds the globalperoperty. Then on click just changes the localproperty and not global one.
-
Normally that works but i have not so much elements.
My Element is a Button and it is just a Rectangle with some variables and a mouse area. This button i use as component in other qmls. And now to add additional Items for a workaround i don't want, because i think it is not a "nice" solutions, i hoped that i found a more correct way to "copy" just the value from a property to a new property.
My actual workaround is to have local propertys and no link to my globalconfig. -
found a work around.
just implement the GlobalConfig in following ways
property QtObject gConfig: GlobalConfig {}
and than
property Gradient offGradient: gConfig.offlineGradient
it works