PDA

View Full Version : Preventing drop/drag outside the main window



ucomesdag
26th February 2007, 03:31
void floorBoard::dragMoveEvent(QDragMoveEvent *event)
{
QByteArray data = event->mimeData()->data("text/uri-list");
QString uri(data);

if ( event->mimeData()->hasFormat("application/x-stompbox") ||
uri.contains(".syx", Qt::CaseInsensitive) &&
event->answerRect().intersects(this->geometry()) )
{
if (children().contains(event->source()))
{
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
};
} else {
event->ignore();
};
};

I tried with adding event->answerRect().intersects(this->geometry()) but you can still drag items outside the mainwindow?

Bit lost here, I want the drag to stop when we are outside the window but it is still active when moving over other apps like firefox.

aamer4yu
26th February 2007, 04:51
Change the mime data type of the drag event.
If you want only your application should handle the drag drop event, use some mime data type which other applications dont understand.

ucomesdag
26th February 2007, 05:28
Change the mime data type of the drag event.
If you want only your application should handle the drag drop event, use some mime data type which other applications dont understand.

Uh like? Even "snork" as mime type works on some greedy apps they just take everything :)

aamer4yu
26th February 2007, 05:38
Uh like? Even "snork" as mime type works on some greedy apps they just take everything :)

hmm... i am not sure how to disable the drag and drop of other application from your application. But one thing more I can suggest.
You can check the window/ widget which accepted the drop by drag->target() function. Hence based on the window that accepted the drag, you can perform actions in your application. Hope this might help you :confused:

ucomesdag
26th February 2007, 06:06
You can check the window/ widget which accepted the drop by drag->target() function. Hence based on the window that accepted the drag, you can perform actions in your application.

Sorry ain't working either, I can still drop my widgets on firefox.

wysota
26th February 2007, 11:42
Setting "Snork" is not enough (should be application/x-snork anyway). You have to make sure there are no other mime-types set, especially text/plain. How do you create the drag in the first place?