Results 1 to 2 of 2

Thread: QSortFilterProxyModel signal and selection confusion

  1. #1
    Join Date
    Apr 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?

    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.

    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?

Similar Threads

  1. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 19:54
  2. Replies: 1
    Last Post: 26th August 2007, 07:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.