PDA

View Full Version : proxy model, selection not visible in a table view (QTableView,QSortFilterProxyModel)



wojtekw
26th February 2009, 19:06
Hi,

I'm presenting model data in a MyTableView (subclassed from QTableView), which has the following selection settings:
mView->setSelectionBehavior(QAbstractItemView::SelectRows );
mView->setSelectionMode(QAbstractItemView::ExtendedSelect ion);

Due to some other restrictions, my custom model is subclassed from QAbstractItemModel and is "projected" on QTableView through MySortFilterProxyModel subclassed from QSortFilterProxyModel.

In custom model I've reimplemented: index, parent, rowCount, columnCount, data, setData, flags, setHeaderData, headerData. In custom proxy model I've reimplemented: index, parent, rowCount, columnCount, data, filterAcceptsRow, filterAcceptsColumn, lessThan, flags, mapFromSource, mapToSource.

The problem is that MyTableView doesn't show anything selected (I always see unselected rows) even though the debug printout from its indexAt(...) shows correctly what model index the mouse is clicking/moving over.

After playing around a bit with different configurations I could see selected rows in MyTableView but only when I removed MyProxyModel or removed and replaced MyItemModel with QStandardItemModel.

1. No selection is visible in MyTableView (although I'm getting data from correct model indices):

QAbstractItemModel...........QSortFilterProxyModel ...........QTableView
.............|.................................... .......|................................|
.............|.................................... .......|................................|
....MyItemModel -----------------> MyProxyModel --------> MyTableView (result: ExtendedSelection set but no selection visble at all)


2. Rows are visibly selected in MyTableView (although ExtendedSelection doesn't work - multple rows can be selected only by Ctrl key + Left Mouse Button):

QAbstractItemModel QTableView
.............|.....................|
.............|.....................|
MyItemModel -----> MyTableView (result: ExtendedSelection set but single row selection only available)

3. Selection works perfectly:

....................................QTableView
............................................|
............................................|
QStandardItemModel -> MyTableView (result: ExtendedSelection set and works perfectly)

What am I missing?
Thanks in advance for any suggestions.
W.

d_stranz
18th November 2009, 23:21
I realize this is an old post, but did you find a solution?

I am seeing exactly the same problem. The proxy model documentation and examples is just too sparse to give any clues as to what is wrong.

-- Later: Never mind --

I got a hint from reading another post here; I implemented flags() in my proxy to return what QAbstractItemModel *says* is the default, but apparently isn't: ItemIsEnabled | ItemIsSelectable. When I did that, all works.