drag and drop from outside qt application
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
Re: drag and drop from outside qt application
Yes, in principle. The most portable way is to see if the mime data contains URLs.
For example:
Code:
{
public:
Widget()
{
setAcceptDrops(true);
}
{
foreach
(QUrl url, event
->mimeData
()->urls
()) if (QFileInfo(url.
toLocalFile()).
suffix().
toUpper()=="PNG") {
event->acceptProposedAction();
return;
}
}
{
foreach
(QUrl url, event
->mimeData
()->urls
()) {
QString filename
= url.
toLocalFile();
if(suffix=="PNG")
{
event->acceptProposedAction();
// do something
continue;
}
}
}
};