[Solved] Delegate stops working when applying filter
I've an already working model/view implementation using QAbstractTableModel, QStyledItemDelegate and a QTableView, so far so good. After this I needed to add a column filter, so I used QSortFilterProxyModel and here is when the problem arises. The filtering works fine but when the position of columns changes, the delegate stop working. I assume this happens because the column index has changed, so the delegate for the fifth column stops working because the fifth column is now the second. This is all about, right now I'm stuck.
Any idea about how to solve this?
Thanks in advance.
This can not be answered in general.
It highly depends on your delegate.
If the delegate relies on the column number, then you might have a problem. You could check, whether the used model is a proxy and map the index to the source model index. But proxy models may be cascaded.
You could also insert a custom data role and get that data from the model to check, how to behave as delegate (like MY_DATA_ROLE = UseRole + 1; MY_DATA_ROLE might return the original column index).
You are right, as well as you thought my delegate relies on the column number.
I already found a solution that solves my problem and on an easier way. This resides on change the delegate to relies on the column name (the columns name never changes) rather than their number.
Thanks for your suggestions and your quick answer.