How to override QAbstractItemModel::parent() in QSortFilterProxyModel?
-
I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?
-
I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?
@Ilya-Andreev I don't understand your use case. A QObject based object can only have ONE parent, returning arbitrary object as parent which is not actual parent will not change the parent/child relationship.
-
I think I need to clarify: I want to redefine the
QModelIndex QAbstractItemModel::parent(const QModelIndex &index) constnot
QObject * QAbstractItemModel::parent() -
I think I need to clarify: I want to redefine the
QModelIndex QAbstractItemModel::parent(const QModelIndex &index) constnot
QObject * QAbstractItemModel::parent()@Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:
QModelIndex QAbstractItemModel::parent(const QModelIndex &index) constWell since that is virtual you can in principle override the override in
QSortFilterProxyModelby sub-classing that. Whether it will behave as you desire/safely I do not know. -
@Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:
QModelIndex QAbstractItemModel::parent(const QModelIndex &index) constWell since that is virtual you can in principle override the override in
QSortFilterProxyModelby sub-classing that. Whether it will behave as you desire/safely I do not know.@JonB Unfortunately, overriding this function has no effect on the tree structure. Perhaps there is another way to redefine the parent without changing the original elements.
-
I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?
@Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:
I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?
How is the view supposed to know that it needs to check the parent() of a particular item again?
The intended path to implement this is via QAbstractItemModel::beginMoveRows and QAbstractItemMode::endMoveRows, or emit the signals mentioned in the first link directly. If the change is complicated enough, use QAbstractItemModel::beginResetModel and QAbstractItemModel::endResetModel.
-
Thanks for the answer, I'll try it and say what happened.