Find the selected index first:
{
QList <QStandardItem
*> lst
= model
->findItems
(name
);
//assuming model is the field of the class if (lst.size() > 0)
return model->indexFromItem (lst[0]);
else
}
const QModelIndex CMyClass::index_from_name (const QString &name)
{
QList <QStandardItem *> lst = model->findItems (name); //assuming model is the field of the class
if (lst.size() > 0)
return model->indexFromItem (lst[0]);
else
return QModelIndex();
}
To copy to clipboard, switch view to plain text mode
Then, to select the item by the filename, do something like this:
tree_view->scrollTo (index);
QModelIndex index = index_from_name (filename);
tree_view->selectionModel()->setCurrentIndex (index, QItemSelectionModel::Select);
tree_view->scrollTo (index);
To copy to clipboard, switch view to plain text mode
Bookmarks