Alex Rivera | Logout

How do I get a selection model to work with a proxy model?

Asked 2008-09-25T22:35:42.970
10

I have a model and two views set up like this:

Model ---> OSortFilterProxyModel ---> OListView
Model ------------------------------> OTableView

When the user selects something in one of the views, I want the other view to mirror that selection. So I thought I'd use a QSelectionModel to link them together. But this does not work. I have a feeling it is because the views think they have two different models, when in fact they have the same model. Is there a way to get this to work?

Edit
Report

1 Answer

1

You propably need to use void QItemSelectionModel::select combined with QAbstractProxyModel::mapSelectionFromSource and QAbstractProxyModel::mapSelectionToSource. In QListView's selectionChange signal handler you should have

tableView->selection()->select(
    proxyModel->mapSelectionToSource(selected),
    QItemSelectionModel::ClearAndSelect);

and analogically with mapSelectionFromSource in QTableView's signalChange signal handler.

Note that i am not sure if Qt will prevent infinite recursion when table will change selection of list which in turn will change selection of table and so on...

answered 2011-09-19T13:32:54.403

Your Answer