PDA

View Full Version : QTreeWidget - Edited Rows



Preeteesh
18th June 2007, 11:51
Hi,

I have a QTreeWidget with 1 editable column. If a user edits any value in any rows i want to keep track of those rows which were edited. Is there some way to do that.

If possible please give some sample code.

Thanks...

wysota
18th June 2007, 12:19
What do you mean by "keep track"? Know which were edited or know history of values in each field?

Preeteesh
18th June 2007, 14:32
Hi,

By keep track i mean know each rows which were edited as well as the values in the columns of each rows that were edited. Actually i have a file from which i parse the data and show it in QTreeWidget. Now a user cam edit the values and then can save. I need to copy the orginal file and change the values which user have updated in that file.

Thanks.

wysota
18th June 2007, 15:58
If you need the full history then I suggest having a role "previousvalues" in the model/item and store a list of previous values there. Then you can query for the data with this role and see if anything is there. But I'd strongely suggest using the model approach so that you can reimplement setData() and make sure nothing screws up your data. Then you can reimplement submit() and do the saving in there.

Preeteesh
18th June 2007, 16:03
Can you provide me with some example or sample code to that. That will be helpful.

Thanks....

wysota
18th June 2007, 16:44
I can't, sorry - it highly depends on the data backend. And if you ask about implementing an own model, search the forum and take a look at the wiki and Qt reference manual.

Assuming you're not a newbie (if you're posting this question in Qt programming and not Newbie), you can probably handle reimplementing data() and setData() in for instance QStandardItemModel. And if you're a minimalist, you don't have to do even that. Just reimplement setData() for your custom tree widget item. Just make sure you always use proper methods when manipulating the object.