QSortFilterProxyModel signal and selection confusion
Hi all,
I am using a QSortFilterProxyModel to display a filtered view of a QAbstractTableModel. Now, the following problem occurrs:
- the proxyModel does not emit a "selectionChanged" signal, but...
- the tableModel emits a selectionChanged signal, but the model indices refer to the filtered model.
- if I select a number of items in the view and then change the filter rules of the proxy model, I get a filtered view of the selection. So far so good. However, if I clear the filter rule again *without having changed any selection*, I have extra items selected in the view!!! For example, items 1,2,3 are selected. Then the filter rule is changed so that item 3 is not visible; now items 1 and 2 are selected. Not the filter rule is cleared and all of a sudden items 1,2,3,4,5 are selected. Strange.
My question: What it the proper way to handle selections with a proxy model? I do need to get a signal when the selection is changed, either due to the user clicking the view, or due to filter rules changing (this narrowing down the existing selection).
Thanks for any advice
Pascal
Re: QSortFilterProxyModel signal and selection confusion
Quote:
Originally Posted by pascal123
I am using a QSortFilterProxyModel to display a filtered view of a QAbstractTableModel. Now, the following problem occurrs:
- the proxyModel does not emit a "selectionChanged" signal, but...
- the tableModel emits a selectionChanged signal, but the model indices refer to the filtered model.
Why is that a problem? "Selection" is a property of the view (and is handled by a selection model) and not the data model. Why should a proxy model emit it?
Quote:
However, if I clear the filter rule again *without having changed any selection*, I have extra items selected in the view!!! For example, items 1,2,3 are selected. Then the filter rule is changed so that item 3 is not visible; now items 1 and 2 are selected. Not the filter rule is cleared and all of a sudden items 1,2,3,4,5 are selected. Strange.
I think this is usually refered to as a bug. There are several bug reports on using QSortFilterProxyModel. If none of them matches your problem, you can make your own report.
Quote:
My question: What it the proper way to handle selections with a proxy model? I do need to get a signal when the selection is changed, either due to the user clicking the view, or due to filter rules changing (this narrowing down the existing selection).
Do you use signals from QItemSelectionModel which is assigned to the view?