Solved Add a variable to QFileSystemModel
-
Hi,
I would like to make a derived class of QFileSystemModel which has one more variable/role to set the selection state of a file. Is there an easy way to do this?
-
Selections are normally not managed by the model but from the
QItemSelectionModel
in the view -
Yes this is true. But I have the problem, that I want to be able to sort my model, e.g. for the filename. If an item has been selected and I sort the model in the view, the selection stays at the place where it was and is not updated. E.g. if I have items 0 to 10 in alphabetical order and select item 1 and hit the sortingIndicator the items get sorted in inverse alphabetical oder and item one becomes 9, but selection stays at 1. I thought I try to solve this via adding the selection state to the model and later set the QItemSelectionModel indices according to my variable state.
Is there an easier/better way to do it?
-
https://forum.qt.io/topic/90202/treeview-of-qfilesystemmodel-remember-selection-after-sorting probably provides the answer for my actual problem. Just out of interest, would there be an easy way to add a variable to each item in a tree model?
-
@maxwell31 In a generic tree model (like
QStandardItemModel
) yes, inQFileSystemModel
you'd need a bit of hacking