void XXXX::mouseMoveEvent(QMouseEvent *event)
{
this->viewport()->setCursor(Qt::PointingHandCursor);
QString fileName /*=指向一个本地存在的文件 */;
if (event->buttons() & Qt::LeftButton)
{
int distance = (event->pos() - _startPos).manhattanLength();
if (distance >= QApplication::startDragDistance() && !this->rect().contains(event->pos()))
{
QMimeData *mimeData = new QMimeData;
mimeData->setData("drag/fileName", fileName.toUtf8());
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(event->pos());
drag->exec(Qt::CopyAction, Qt::CopyAction);
}
}
return XXXX::mouseMoveEvent(event);
}
关键点:执行操作设置为 Qt::CopyAction 。