01-06-2013 11:16 AM
I have a checkbox that's binded to a property.
When the user touches the checkbox the property will change so I can save it.
The problem is that onCheckedChanged is called whenever I modify the value.
I want to find a method to know when the user touched the checkbox but also have the property binding
How can I differentiate between onCheckedChanged and the moment I touch the checkbox on the screen
CheckBox {
id:check
checked: ListItemData.checking;
onCheckedChanged : {
ListItemData.checking= 0;//or do something to update my model
}
Ps also when the checkBox is created onCheckedChanged is called if ListItemData.checking is ture
Solved! Go to Solution.
01-06-2013 11:26 AM
Try blocking the signals when changing "checked" from code. This thread should help:
01-06-2013 04:48 PM
yes thanks for the fast answer this helps a lot but a problem still remains.
When the checkBox component is created OnChecked is called in and if the checkbox binded property is true it will mess my model up (making the propery value 0 ,when it should be 1)
A solution that solves the problem is declaring a property firstcreated and when onCretedCompleted is called initialize it with TRUE,Then in OnChecked check first if firstcreated is TRUE ...... then give it the value FALSE
If someone has a better ideea on how to fix this better I'm all ears ![]()
01-06-2013 05:21 PM
01-06-2013 10:26 PM
01-07-2013 06:37 AM
Hi ,
You can maintain flag variable for check wheather it is first time or not.
CheckBox {
property bool flag: true
text: "Button"
onCheckedChanged: {
if (flag) {
flag = false;
} else {
//write you code here
}
}
}flag variable like a private member variable of checkbox class.
so when row generate it will make different copy of flag viriable for every checkbox object.
Thank You.
01-08-2013 02:14 PM - edited 01-08-2013 02:34 PM
@Raj Unfourtunately this won't work because some of the elements won't be checked first time so onchecked won't be called ,and if you check them afterwards because of the flag they won't be checked on(in the model).
I'm using a list forgot to mention that , peter9477 solution works great.
Thanks everyone