PDA

View Full Version : Qt get absolute directory path from Qtreeview



ashish18
3rd August 2015, 12:39
Hi QT,

I have a Qtreeview for exploring local drives content and i am dropping a file from another Qlistview to the Qtreeview. Now i want to get absolute path of that directory in the Qtreeview where i am dropping the directory/file from Qlistview.
For example I have a directory named "example" in the D drive then i want to get "D:/example". Right now i am able to call drop function and getting name of that destination directory where i am dropping the source directory/file. I need this because i have to call a hand written function to copy the source dir/file to that destination path using some command.

yeye_olive
3rd August 2015, 14:30
The models viewed by the QListView and QTreeView must agree on a format (more precisely, a MIME type) representing the data being dragged and dropped.

For instance, you could choose the standard text/uri-list MIME type, and represent the files begin dragged as the list of their URLs. QMimeData::setUrls() will let you encode a list of QUrl as MIME data.

Then, follow the documentation that explains how to set up the source and target models and views so that they share this MIME type to drag and drop files:
model-view-programming.html#using-drag-and-drop-with-item-views
The source model will need custom implementations of QAbstractItemModel::mimeTypes() and QAbstractItemModel::mimeData(). The target model will need custom implementations of QAbstractItemModel::mimeTypes(), QAbstractItemModel::dropMimeData(), and maybe QAbstractItemModel::canDropMimeData().

anda_skoa
3rd August 2015, 14:59
I have a Qtreeview for exploring local drives content and i am dropping a file from another Qlistview to the Qtreeview. Now i want to get absolute path of that directory in the Qtreeview where i am dropping the directory/file from Qlistview.

You forgot to mention what kind of model you are using.

For a QFileSystemModel that would be trivial, but if you have a custom model, then you'll need to implement support for this information there.

Cheers,
_