QStandardItemModel & QStandardItem instance 10+ items between 2 models?
-
wrote on 10 Nov 2018, 22:41 last edited by
Hey
I'm tinkering with idea of instancing data between 2 standardItemModels. Say Model A has 20 nodes, and modelB has 10 nodes. I would like to share the nodes from modelA to modelB, let them be "their own little hierarchy" but if I change their order in modelA I'd like to see the same action happen in modelB... humh I guess I would not be able to parent them anywhere in modelB to native modelB nodes, because that would break everything. But I do wonder... has any1 tried this before?
Regards
Dariusz
TIA -
Not possbile. Model takes the ownership of items when set. So two model cannot own the same item. It will be a big trouble. You can use QSortFilterProxyModel if your interest is share the subset of data to another model.
-
wrote on 11 Nov 2018, 07:36 last edited by
Of course if you inherit abstract model directly and implement your own data handling the data can be anything you want, even shared, provided that you know what you're doing.
-
wrote on 11 Nov 2018, 08:46 last edited by
@dheerendra thanks! I had a feeling that was the case, but QSortFilterProxyModel is a very interesting discovery! I used it a few times but humh... I will look into that more! Thanks! If you have any suggestions/tutorials/read please shoot away, bit lost atm as to what to look for there.
@Eeli-K Yep, I subclass QAbstractItemModel & created my own treeItem from the ground up so I have full control over these 2 entities. I Extended QtreeView with some "helper" handlers of my data/model but that's it. Did not touch QModelIndex to me its black magic ;- ) Will think about solving that internally somehow. If I were to redirect the read of some widgets, what would I need to extend more? index/data/row functions? Hmm I need to think about it more. Getting some lightbulbs slowly here but I wonder if it's backward. Atm, I'm thinking that each of the virtual functions I had to overload would have to return native model data 1st and once that's done, return the instanced model/items data... uhhh getting complicated humhhhh humhhh humhhhh interesting. Thanks!
Regards
Dariusz
TIA
4/4