Yes, thats what I am doing right now;
#include "customtreeview.h"
customtreeview
::customtreeview(QWidget * parent
){
}
void customtreeview
::mousePressEvent(QMouseEvent *event
) {
if (event->button() == Qt::LeftButton)
{
QFileSystemModel *tempmodel = qobject_cast<QFileSystemModel *>(model());
QList<QUrl>urllist;
QString filename
=tempmodel
->filePath
(tempindex
);
emit setpreview(filename);
urllist.
append(QString("file:"+filename
));
mimeData->setUrls(urllist);
tempmap.fill(Qt::white);
Drag.setPixmap(tempmap);
Drag.setMimeData(mimeData);
Drag.exec( Qt::IgnoreAction );
}
}
#include "customtreeview.h"
customtreeview::customtreeview(QWidget * parent)
{
}
void customtreeview::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
QDrag Drag( this );
QFileSystemModel *tempmodel = qobject_cast<QFileSystemModel *>(model());
QModelIndex tempindex = indexAt(event->pos());
QPixmap tempmap(1,1);
QMimeData *mimeData = new QMimeData;
QList<QUrl>urllist;
QString filename=tempmodel->filePath(tempindex);
emit setpreview(filename);
urllist.append(QString("file:"+filename));
mimeData->setUrls(urllist);
tempmap.fill(Qt::white);
Drag.setPixmap(tempmap);
Drag.setMimeData(mimeData);
Drag.exec( Qt::IgnoreAction );
}
QTreeView::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
I left everything else untouched.
I still struggle to understand how to set drag and drop behaviour correctly.
Bookmarks