Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Get current file path QTreeView
Hello guys. I have to create a function to remove files and folders/subfolders when the user do a right click in an item on the QTreeView. I know that i can use this method QFileInfo QDirModel::fileInfo ( const QModelIndex & index ) const but i only have a QPoint received from customContextMenuRequested(const QPoint&) signal.
Any ideas on how i can do that? How i can get the file path using a QPoint?
You could use QTreeView::indexAt to get the index from the point and then continue the same way you already do
Hope it helps
@ShowContextMenu(const QPoint& pos)
qDebug() << dir.filePath(this->ui->treeView->indexAt(pos));
It will return an empty string. Why? :(
If i call @qDebug() << this->ui->treeView->indexAt(pos).data();@ returns the correct item data.
The index returned by treeView->indexAt() doesn't belong to the QDirModel you just created, it belongs to the model you set on the QTreeView. Use that model and you should be fine
I need more info. How do i do that?
If you have a QTreeView, you have created a model (probably a QFileSystemModel or a QDirModel) somewhere and called treeView->setModel(model), it's that model you have to use
You can also get the model from treeView:
@QXXXModel *model = qobject_cast<QXXXModel *>(treeView->mode());@
Works fine now. Thank you :D