View Full Version : Set QDrag mimeData
Imhotep
3rd September 2016, 18:48
I have a class derived from QTableWidget, receiving drag'n'drop from external files and displays the name. The default action is Qt::CopyAction, and to ensure that the action to be performed is Qt::LinkAction, I must use drag->exec(Qt::LinkAction).
void tableWidget::dropEvent(QDropEvent *event) {
//…
QDrag *drag = new QDrag(this);
//…
}
Since
event->mimeData() returns data as const QMimeData and drag->setMimeData(data) accept argument as QMimeData, there is a way to overcome this problem?
anda_skoa
3rd September 2016, 21:17
I have a class derived from QTableWidget, receiving drag'n'drop from external files and displays the name. The default action is Qt::CopyAction, and to ensure that the action to be performed is Qt::LinkAction, I must use drag->exec(Qt::LinkAction).
QDrag::exec() starts a new drag operation.
Are you sure you want to do that?
Your description sounds like you want the incoming drag to perform the LinkAction.
See QDropEvent::setDropAction() for doing that.
Cheers,
_
Imhotep
3rd September 2016, 22:06
Tried this
void DTableWidget::dropEvent(QDropEvent *event) {
event->setDropAction(Qt::LinkAction);
event->accept();
//…
}
Still perform Qt::CopyAction
anda_skoa
4th September 2016, 09:48
Have you checked if the LinkAction is part of the QDropEvent::possibleActions() list?
It could very well be that the drag's source does not support that.
Cheers,
_
Imhotep
4th September 2016, 12:10
Seems to be
void DTableWidget::dropEvent(QDropEvent *event) {
qDebug() << event->possibleActions();
event->setDropAction(Qt::LinkAction);
event->accept();
//…
}
QFlags<Qt::DropAction>(CopyAction|MoveAction|LinkAction)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.