Results 1 to 4 of 4

Thread: Showing selected rows in a separate table

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

    Default Showing selected rows in a separate table

    Hi,

    I would like to have 2 separate tables, one showing all the items, and the other one the current selection of the original items.

    My current solution is as follows; I create a proxy of the original model, to which I also pass its item selection model. I overwrite the QSortFilterProxyModel::filterAcceptRow() function, and return true only if the row is selected. In order to ensure that the second table is updated each time that the selection is changed, I connect the signal selectionChanged which calles a wrapper slot that just invokes QSortFilterProxyModel::filterChanged(). I attach the minimal code that implements what I described above and a screenshot showing the desired behavior.

    Although it works, I don't like this solution for the following reasons:
    1) filterAcceptRow uses the info from the selection model and not from the source model to decide whether a row should be filtered or not, which may not be the neatest solution
    2) filterChanged() exists only from Qt4.2 and I need my application to be compatible with Qt4.1 too
    3) if I understand well, filterChanged() recalculates accepted rows for all the indexes of the source models, and not only the ones which were removed from/added to a selection. Given that I can have tens of thousands of rows in the original model, this does not look like an optimal solution.

    Does anyone have a better idea of implementing such functionality?
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Join Date
    Oct 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Showing selected rows in a separate table

    Hello, isn't there any model/view expert willing to help? Any suggestion would be greatly appreciated!

    Thanks

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Showing selected rows in a separate table

    One option could be to wrap the QItemSelectionModel into a QAbstractListModel. This way the model would operate on the selected indexes only (whereas the proxy operates on the whole source model).
    J-P Nurmi

  4. #4
    Join Date
    Oct 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Showing selected rows in a separate table

    Thanks a lot for your hint! Here is what I did, I created a class ProxyModel which extends QAbstractListModel and takes the source model and the item selection model as arguments. The proxy model contains the list of selected indexes from the source model. I connect the QItemSelectionModel::selectionChanged signal to a slot which updates the Proxy Model, ie. removes the indexes which were diselected and appends indexes which were selected. I also overwrite the data() method in the Proxy Model so that it returns data from the source model.

    You can find a working implementation attached, there might be some additional checkings/optimizations to be done, but it shows the idea. Comments are welcome.
    Attached Files Attached Files

Similar Threads

  1. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 12:49
  2. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06

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.