PDA

View Full Version : drag and drop from outside qt application



elflord
16th February 2009, 15:19
Hello all:

I would like to drag an image on my file system and drop to my qt application
i've read the Qt documents and it seems the drag and drop function works within the same application window

so my question is : is it the same way to program drag and drop in the two situations ?

thanks

spud
16th February 2009, 16:40
Yes, in principle. The most portable way is to see if the mime data contains URLs.
For example:


class Widget : public QWidget
{
public:
Widget()
{
setAcceptDrops(true);
}
void dragEnterEvent(QDragEnterEvent *event)
{
foreach(QUrl url, event->mimeData()->urls())
if (QFileInfo(url.toLocalFile()).suffix().toUpper()=="PNG")
{
event->acceptProposedAction();
return;
}
}
void dropEvent(QDropEvent *event)
{
foreach(QUrl url, event->mimeData()->urls())
{
QString filename = url.toLocalFile();
QString suffix = QFileInfo(filename).suffix().toUpper();
if(suffix=="PNG")
{
event->acceptProposedAction();
// do something
continue;
}
}
}
};