I have two questions please.
first, I dont understand how this cast from qt's examples (Tree Model Completer) works:

Qt Code:
  1. QAbstractItemModel *completionModel = completer->completionModel();
  2. QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(completionModel);
To copy to clipboard, switch view to plain text mode 

according to qt's class references, QAbstractItemModel doesnt inherit from QAbstractProxyModel.
although indeed completer->completionModel() is a QStandardItemModel, but it makes no deference (it inherits only from QAbstractItemModel that in turn doesnt inherit from QAbstractProxyModel).

complete code of that member function is this:

Qt Code:
  1. void MainWindow::highlight(const QModelIndex &index)
  2. {
  3. QAbstractItemModel *completionModel = completer->completionModel();
  4. QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(completionModel);
  5. if (!proxy)
  6. return;
  7. QModelIndex sourceIndex = proxy->mapToSource(index);
  8. treeView->selectionModel()->select(sourceIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
  9. treeView->scrollTo(index);
  10. }
To copy to clipboard, switch view to plain text mode 

another question is why do we use a QAbstractProxyModel here?
this modified code works too:

Qt Code:
  1. void MainWindow::highlight(const QModelIndex &index)
  2. {
  3. /* QAbstractItemModel *completionModel = completer->completionModel();
  4.   QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(completionModel);
  5.   if (!proxy)
  6.   return;
  7.   QModelIndex sourceIndex = proxy->mapToSource(index); */
  8. treeView->selectionModel()->select(/* sourceIndex */ index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
  9. treeView->scrollTo(index);
  10. }
To copy to clipboard, switch view to plain text mode 

qt 4.4.3