You can calculate the full path with the following way. First you need to track mouse clicks on the QTreeView
with connecting the clicked()
signal to the appropriate slot:
connect(treeview, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onItemClicked(const QModelIndex &));
In your slot you can call the helper function that will return the full path of the clicked tree node:
void TreeView::onItemClicked(const QModelIndex &index)
{
QString path = fullPath(index);
// ..
}
QString TreeView::fullPath(const QModelIndex &index)
{
QString path('/');
QModelIndex parent = index;
while (parent.isValid()) {
path.prepend('/' + parent.data().toString());
parent = parent.parent();
}
return path;
}