PDA

View Full Version : Moving Items in QTableView with QSortFilterProxyModel



Rudolf Rendier
6th February 2012, 14:20
I need to implement a view that represents data in multiple columns.
The items in the list can be filtered using the proxymodel. So I ended up using the QTableView

What I need to do is move the items in the view by using a set of pushbuttons (up, down, top, bottom)

I'm having problems when the filter is active, because the movement operations are happening in the model, not the view.
I.e. my filtered view shows the items with verticalheader index 1, 5, 8, 10. If I move 8 down by one, it becomes 9 and is it will still be listed above 10.
Can I find out the source of the line below (or above, for up), so I can swap them?

Using drag & drop only works properly when I'm dragging the index in the verticalheader;
if I allow the items to be draggable and droppable, I can mess up the table by dragging an item from one column onto the other.
(The complete rows indents onto that column)
Is there a way to prevent this from happening?

Any guidance would be greatly appreciated.

wysota
6th February 2012, 15:07
Use QAbstractProxyModel::mapToSource() and QAbstractProxyModel::mapFromSource() to map between models.