what is the signal for qtreeview changed

what is the signal for qtreeview changed



There is a dictionary taken from JSON file, that is represented by QTreeView QStandardItemModel.


QTreeView


QStandardItemModel



A user can reorganize QTreeView(add, delete, drag-n-drop) and rename items.


QTreeView



The goal is: call function that reads changed QTreeView, makes the dictionary and writes it to initial JSON file.


QTreeView



I can do it by pressing a QPushButton after changes occurred or by binding that function to every change e.g. call function when an item is deleted, call function when an item is added, call a function when an item is renamed and so on.


QPushButton



Is there any way to call a function if any of changes occur? Is there such a signal that corresponds to all of the mentioned changes?





QAbstractItemModel::dataChanged() and/or QAbstractItemModel::layoutChanged() signals might help.
– vahancho
Jun 22 '15 at 13:18


QAbstractItemModel::dataChanged()


QAbstractItemModel::layoutChanged()





A QTreeView is a view, so it's a widget. Widgets normally don't signal their updates, instead they are delivered an event when they should update. Did you mean that you wish to know when the model has changed? If so, you should read the documentation: see introduction to model view programming.
– Kuba Ober
Jun 22 '15 at 13:49


QTreeView




2 Answers
2



The rowsMoved and itemChanged signals do what you think they do. See http://doc.qt.io/qt-4.8/qstandarditemmodel.html


rowsMoved


itemChanged





I'm looking for the way avoiding bindings function to each one change. Is there any signal for all of changes.
– Sergii Artele
Jun 22 '15 at 13:23





@SergiiArtele How do you know that there are "all" changes - i.e. why do you presume that there is more than one change? Alternatively, if you think that "binding" a function to each kind of change is to be avoided: well, it can't be, since there is no signal that just says "hey, something changed". There are different kinds of changes: structural and non-structural, and it differs quite a bit how you might handle them. Perhaps tell us what you need to do with such changes first.
– Kuba Ober
Jun 22 '15 at 13:50






Ok, I meant to use such a signal that covers any of changes I do. Like selectionChanged may be used to cover wheither item was clicked or selected by arrows on the keyboard or keyboardSearch.
– Sergii Artele
Jun 23 '15 at 9:49


selectionChanged


keyboardSearch



As @vahancho suggests in the comments, you should connect to the layoutChanged signal. All models should emit this immedaitely after making any changes which could affect the view. So this will include sorting and filtering, as well as re-ordering, editing, deleting, etc.



The dataChanged signal is similar, but only really useful if you want to monitor specific items.





layoutChanged works in my case only for drag'n'drop. It doesn't work when I add, delete or rename item.So I will use itemChanged when renaming occures and I will call function that reads tree and saves its content to JSON file when delete or add
– Sergii Artele
Jun 23 '15 at 9:42


itemChanged





@SergiiArtele. Sorry - it seems I've never fully tested what these signals do, and so I was mislead by the Qt docs.
– ekhumoro
Jun 23 '15 at 15:49



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)