Sure, I attached the proxyFilter code. What's also interessting that if I click into the treeview I get a bunch of cout's from the setData instead just a single one.

Qt Code:
  1. snip main.cpp
  2.  
  3. TestModel model;
  4. QSplitter *splitter = new QSplitter;
  5. QTreeView *tree = new QTreeView(splitter);
  6. QTableView *table = new QTableView(splitter);
  7.  
  8. table->setModel(&model);
  9. table->setRootIndex(QModelIndex());
  10.  
  11. ProxyFilter filterModel;
  12. filterModel.setSourceModel(&model);
  13. tree->setModel(&filterModel);
  14.  
  15. splitter->setWindowTitle("Test views");
  16. splitter->show();
  17.  
  18. return app.exec();
  19. }
To copy to clipboard, switch view to plain text mode 

proxyFilter.cpp:
Qt Code:
  1. #include "proxyFilter.h"
  2. #include <iostream>
  3.  
  4. ProxyFilter::ProxyFilter() {
  5. }
  6.  
  7. ProxyFilter::~ProxyFilter() {
  8. }
  9.  
  10. QModelIndex ProxyFilter::mapFromSource (const QModelIndex & sourceIndex) const {
  11.  
  12. std::cout << "mapFromSource" << std::endl;
  13.  
  14. if(sourceIndex.isValid())
  15. return createIndex(sourceIndex.row(), sourceIndex.column());
  16. else
  17. return QModelIndex();
  18. }
  19.  
  20. QModelIndex ProxyFilter::mapToSource (const QModelIndex & proxyIndex) const {
  21.  
  22. std::cout << "mapToSource" << std::endl;
  23. return sourceModel()->index(proxyIndex.row(), proxyIndex.column());
  24. }
  25.  
  26.  
  27. int ProxyFilter::columnCount(const QModelIndex & parent) const {
  28.  
  29. // return sourceModel()->columnCount(parent);
  30.  
  31. // filter out all cols - keep only col = 0
  32. return 1;
  33.  
  34. }
  35.  
  36. int ProxyFilter::rowCount(const QModelIndex & parent) const {
  37. return sourceModel()->rowCount(parent);
  38. }
  39.  
  40.  
  41. QModelIndex ProxyFilter::index(int row, int column, const QModelIndex& parent) const {
  42.  
  43. return sourceModel()->index(row, column, parent);
  44.  
  45. }
  46.  
  47. QModelIndex ProxyFilter::parent(const QModelIndex&) const {
  48.  
  49. return QModelIndex();
  50. }
  51.  
  52. QVariant ProxyFilter::data(const QModelIndex & index, int role) const {
  53.  
  54. std::cout << "data: row =" << index.row() << " col=" << index.column() << std::endl;
  55. return sourceModel()->data(index, role);
  56.  
  57. }
  58.  
  59. bool ProxyFilter::setData(const QModelIndex &index, const QVariant &value, int role) {
  60.  
  61. std::cout << "setData: row =" << index.row() << " col=" << index.column() << std::endl;
  62. return sourceModel()->setData(index, value, role);
  63.  
  64. }
  65.  
  66. Qt::ItemFlags ProxyFilter::flags(const QModelIndex &index) const {
  67.  
  68. return sourceModel()->flags(index);
  69.  
  70. }
  71.  
  72. void ProxyFilter::setSourceModel(QAbstractItemModel *sourceModel) {
  73.  
  74. connect(sourceModel, SIGNAL(modelReset()), this, SIGNAL(modelReset()));
  75. QAbstractProxyModel::setSourceModel(sourceModel);
  76.  
  77. }
To copy to clipboard, switch view to plain text mode 

proxyFilter.h:
Qt Code:
  1. #ifndef PROXYFILTER_H
  2. #define PROXYFILTER_H
  3.  
  4. #include <QAbstractProxyModel>
  5. #include <QAbstractItemModel>
  6.  
  7. class ProxyFilter : public QAbstractProxyModel {
  8.  
  9. Q_OBJECT
  10.  
  11. public:
  12.  
  13. ProxyFilter();
  14. ~ProxyFilter();
  15.  
  16. int columnCount(const QModelIndex & parent = QModelIndex()) const;
  17. int rowCount(const QModelIndex & parent = QModelIndex()) const;
  18.  
  19. QModelIndex mapFromSource (const QModelIndex & sourceIndex) const;
  20. QModelIndex mapToSource (const QModelIndex & proxyIndex) const;
  21.  
  22. QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
  23. QModelIndex parent(const QModelIndex&) const ;
  24.  
  25. QVariant data(const QModelIndex & index, int role) const;
  26. bool setData (const QModelIndex &index, const QVariant &value, int role);
  27.  
  28. Qt::ItemFlags flags(const QModelIndex &index) const;
  29.  
  30. void setSourceModel(QAbstractItemModel *sourceModel);
  31.  
  32. };
  33.  
  34. #endif
To copy to clipboard, switch view to plain text mode