what is the signal for qtreeview changed

4.1k views Asked by At

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

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

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

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.

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?

2

There are 2 answers

3
mdurant On

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

3
ekhumoro On

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.