@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!
Platform - Linux x86_64
Qt Version - 5.9.3
fontHeight produced a integer value +/- 56
iconHeight produced an integer value ( < fontHeight)
The Role's where not the problem. Please see my updated delegate below (kudos for calling it, the delegate being the problem)
Well this is embarrasing. I did not fully realize what I was coding until I had battled with the delegate all night.
I understood that I was coding a template, and assumed that on each item which was added, the origin remained at [0,0]. This was not the case as there was an offset added of value specified in the sizeHint (in my case, 56). Thus all my QListView's QStandardItem's were in fact there, but drawn over each other.
After changing values and experimenting over a long period (a number of hours), I finally came to the desired result, shown below.
Also, I need to thank scopchanov for his hint into this offset problem
Put a QSortFilterProxy model in-between. then save from the proxy instead of the main model.
connect(currentTableHeader, SIGNAL(sectionClicked(int)), this, SLOT(on_sectionClicked(int))); and void mainWidget::on_sectionClicked(int index) are useless. this is the default behaviour of QTableView, you don't have to implement it manually
My second and main question is then : how to implement correct drag and drop operations with custom QStandardItem which needs to own custom data ?
With the standard item widgets/models you can't drag-n-drop custom item roles.
This makes sense, since the model doesn't know which UserRole+ was set.
It would need to iterate all possible item-role values when creating the drop-data.
The only solution i see is to create your own custom model and reimplement the needed drag-n-drop methods. This also give you full control over your data structure storing the data inside the model.
This is more work, but you will learn a lot and gain some performance (by avoiding the standard-item classes)
It could be something in the Qt Designer ui form I was using. I've found that if I start afresh with a new form rebuilding the ui from scratch, then the view in the new ui does get updated straight away as expected.
I still don't know precisely what was driving the problem, but this "workaround" will do as a solution.
QStandardItemModel model = static_cast<QStandardItemModel>(ui->tree_shot->model());
Instance of which class is ui->tree_shot->model()?
The fact that you cast it to QStandardItemModel does not make it one.
If it is not QStandardItemModel or derived class you are in undefined behavior area.
You should not use static_cast for any of QObject derived class anyway. Use qobject_cast and check that value is not nullptr.
If you are creating model yourself is ui->tree_shot a QTreeWidget?
If it is custom model you probably did not call proper functions when changing the model.
In this case widget will not be updated properly.
The things you have to understand with hierarchical model are:
everything can be done through items
use appendRows (or insertRows) to add one line containing several columns
create a hierarchy on the item that represents the first column with the above appendRows (for instance on "(fffe,e000)" but not on "SQ")
use appendRows (or insertRows) on top level instances only to your model (for instance "(0040,a493)" "CS", "(0040,a504)" "SQ", but not "(0008,0105)" "CS")
To view your hierarchy, create a QTreeView and give it this model.
Thanks for your reply. I will see about QIdentityProxyModel.
I have two or more multiselect widgets (QTableView with checkable items) where the items checked in one multiselect are removed from the others.