[Qt-interest] Drag&Drop on OS X behaves weird
Nikos Chantziaras
realnc at arcor.de
Fri Dec 31 15:16:12 CET 2010
In my application, I allow drag&dropping files. If a file is dropped
into the application's QMainWindow, that file is opened. To do this, I
override dragEnterEvent(QDragEnterEvent*) and dropEvent(QDropEvent*) in
my QMainWindow subclass. The code is very straightforward and short:
void dragEnterEvent( QDragEnterEvent* e )
{
// Only accept the event if there is exactly one URL which
// points to a local file.
if (e->mimeData()->hasUrls() and e->mimeData()->urls().size() == 1
and not e->mimeData()->urls().at(0).toLocalFile().isEmpty())
{
e->acceptProposedAction();
}
}
void dropEvent( QDropEvent* e )
{
if (ok_to_open_a_file) {
schedule_file_open(e->mimeData()->urls().at(0).toLocalFile());
e->acceptProposedAction();
} else {
e->ignore();
}
}
Is this is how the drag&drop functionality of Qt is intended to be used?
Because on OS X I get weird results, mainly the application not
accepting any keyboard inputs anymore after the file is opened. At
least for a while (10 seconds or so.) Furthermore, the application from
which the drag&drop operation originated also freezes for about the same
amount of time (in this case, the Mac Finder). No such problems on Linux.
I'm on Qt 4.7.1.
More information about the Qt-interest-old
mailing list