QSortFilterProxyModel and QTreeView
-
You currently have source model -> your proxy model -> QSortFilterProxyModel -> view.
Any chance you can instead do source model -> QSortFilterProxyModel -> your proxy model -> view ? i.e. filter before applying the transformation.The most desired structure is data - QSortFilterProxyModel - QIdentityProxyModel but Crash occurs due to incorrect mapping in QSortFilterProxyModel
In 99.9999999% of the cases this is due to the implementation of your custom proxy not respecting the strong
QAbstractItemModelcontract.I made a model that inherited the QIdentityProxyModel
Interesting. I'm actually the original aouthor of
QTransposeProxyModel(that basically does the same thing but to the entire model, not only to the children) and I'm pretty sure (and the maintainer of the model-view infrastructure agrees with me) that transformation cannot be done unless:- you modify the Qt internals to add your custom proxy as a friend of
QAbstractItemModel - you pass an invalid index to
QIdentityProxyModel::mapToSource
See this discussion aiming to provide a solution to the problem in Qt6
- you modify the Qt internals to add your custom proxy as a friend of
-
Parent is the parent of Item1, Item2 and Item3 right? Then Item2 and Item3 should not be affected by filtering item1. Only the children are.
And another question: What exactly does the QIdentityProxyModel do??@gde23 said in QSortFilterProxyModel and QTreeView:
Parent is the parent of Item1, Item2 and Item3 right? Then Item2 and Item3 should not be affected by filtering item1. Only the children are.
And another question: What exactly does the QIdentityProxyModel do??Thanks for the answer @gde23
QIdentityProxyModel converts 4 rows to 1 row ! (Listeningly, this is also a kind of mapping ...)
The reason to use it like this is that the data-QSortFilterProxy-QIdentityProxy structure causes a crash as mentioned above.
QSortFilterProxy-I'm not sure if the QIdentityProxy structure is bad or I'm wrong.
What I want most is the data-SortFilterProxy-QIdentityProxy structure.
-
You currently have source model -> your proxy model -> QSortFilterProxyModel -> view.
Any chance you can instead do source model -> QSortFilterProxyModel -> your proxy model -> view ? i.e. filter before applying the transformation.The most desired structure is data - QSortFilterProxyModel - QIdentityProxyModel but Crash occurs due to incorrect mapping in QSortFilterProxyModel
In 99.9999999% of the cases this is due to the implementation of your custom proxy not respecting the strong
QAbstractItemModelcontract.I made a model that inherited the QIdentityProxyModel
Interesting. I'm actually the original aouthor of
QTransposeProxyModel(that basically does the same thing but to the entire model, not only to the children) and I'm pretty sure (and the maintainer of the model-view infrastructure agrees with me) that transformation cannot be done unless:- you modify the Qt internals to add your custom proxy as a friend of
QAbstractItemModel - you pass an invalid index to
QIdentityProxyModel::mapToSource
See this discussion aiming to provide a solution to the problem in Qt6
Thanks for the answer @VRonin
Any chance you can instead do source model -> QSortFilterProxyModel -> your proxy model -> view ? i.e. filter before applying the transformation.
I tried it and Crash came up. I think the reason for crash is because I used InternalPointer as the index passed from QSortFilterProxyModel to QIdentityProxyModel.
Have you ever seen the article that it is not possible to override Mapping in QSortFilterProxyModel?
If not, what should I do?
In 99.9999999% of the cases this is due to the implementation of your custom proxy not respecting the strong QAbstractItemModel contract.
As I read through the answers, am I correct that I am implementing ProxyModel incorrectly?
Because will it need to be fixed?
- you modify the Qt internals to add your custom proxy as a friend of
-
Ok, now I understand what you are doing.
To find out what causes the crash in the approach VRonin suggested, could you try to only apply the filter in a first run to see if it works when used without proxy, and then afterwards add the proxy. Or even better then test the proxy without filter and finally combine them. -
Thanks for the answer @VRonin
Any chance you can instead do source model -> QSortFilterProxyModel -> your proxy model -> view ? i.e. filter before applying the transformation.
I tried it and Crash came up. I think the reason for crash is because I used InternalPointer as the index passed from QSortFilterProxyModel to QIdentityProxyModel.
Have you ever seen the article that it is not possible to override Mapping in QSortFilterProxyModel?
If not, what should I do?
In 99.9999999% of the cases this is due to the implementation of your custom proxy not respecting the strong QAbstractItemModel contract.
As I read through the answers, am I correct that I am implementing ProxyModel incorrectly?
Because will it need to be fixed?
@Qt-Jo-Ha said in QSortFilterProxyModel and QTreeView:
am I correct that I am implementing ProxyModel incorrectly?
Yes, and I'm going even further in saying that it's impossible to create such a proxy correctly in Qt5 without manually building a mirror of the entire tree structure in your proxy or using one of the 2 "hacks" mentioned above due to QTBUG-83911
Generally speaking, however, the easier way to find errors in the model implementation is by using the model test
-
Qt is using logic thats turned
inside-outWith normal programming language,
TreeNodeinherits its properties frommasternode , but not in the qt. Heremasternode inherits from child....FUCKED UP
@macfanpl Please read and respect https://forum.qt.io/topic/113070/qt-code-of-conduct
-
Thanks for the answer, everyone finally solved this problem.
The reason was that the wrong index was created in the index function that was overridden in the last QIdentityProxyModel.
I tried to keep the parent item and the child item separately, so using internalPointer seems to have contributed to the crash.