Important: Please read the Qt Code of Conduct -

How to drag and drop QStandardItems containing file paths in a Treeview to a file on the desktop or another application?

  • I have a treeview which is modeling a file tree. Each item in the TreeView is a QstandardItem that holds a file path. I would like to be able to get the file it referes to and drag the item into another application. The files are all video files so I would like to add the ability to drag and drop into VLC, Adobe Premier etc.

    There are a lot of posts with similar questions but the answers are kind of all over the place so any resources will be of great help.


  • Subclass your QStandardItemModel with something like this:

    class FileItemModel : public QStandardItemModel{
        using QStandardItemModel::QStandardItemModel;
        QMimeData *mimeData(const QModelIndexList &indexes) const override{
            QMimeData *result  = QStandardItemModel::mimeData(indexes);
                QList<QUrl> urls;
                for (auto&& idx : indexes){
                    urls << QUrl::fromLocalFile(; /*this assumes the full path to the file is stored in DisplayRole, change according to your needs*/
            return result; 
        QStringList mimeTypes() const override{
            return QStandardItemModel::mimeTypes() << QStringLiteral("text/uri-list");

Log in to reply