void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle) { QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); QModelIndexList match = m->match(m->index(0,0), TreeItemDT::NR, dive->number, 1, Qt::MatchRecursive); QItemSelectionModel::SelectionFlags flags; QModelIndex idx = match.first(); QModelIndex parent = idx.parent(); if (parent.isValid()) expand(parent); flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select; flags |= QItemSelectionModel::Rows; selectionModel()->select( idx, flags); if (scrollto) scrollTo(idx, PositionAtCenter); }