View Full Version : Drag and Drop PDFs

1st July 2006, 06:09
First of all I'm using the open source edition for windows. (I hope it doesn't limit me from doing this...)

I'm very uncertain about mime-types, but I would like to drag and drop a pdf from the desktop onto my application. Is this possible?

My basic need is to have a section that when I drag and drop a pdf, it is automatically displayed in the section and it is also copied to a specific location. I could use a browse dialog, but dragging and dropping is much more convenient in the end.

Big Duck
1st July 2006, 12:28
Qt should do what you want I think. Take a look at the qtdemo for drag and drop called drop site. I'm sure if you drag a pdf onto it you will see the mime type and data.

Qt open source for windows should be just fine, same functionality as linux,mac...

Do a search on this forum for drag and drop and you'll find many helpfull threads.

For your section, you'll need to subclass something to implement functionality. For instance subclass the widget, and re-define some of these:

virtual void dragEnterEvent ( QDragEnterEvent * event )
virtual void dropEvent ( QDropEvent * event )

You'll have to check that event->mimeData()->hasFormat("application/pdf");
or something similiar. then accept the drop.
I dont know anything about reading pdf's unfortunately.
Good luck

1st July 2006, 17:50
I dont know anything about reading pdf's unfortunately.

There are bunch of soft dedicated to pdf reading; their sources should help :
Xpdf source code (http://www.foolabs.com/xpdf/download.html)
Evince source code (http://live.gnome.org/Evince/GettingEvince)

1st July 2006, 18:10
Thanks. I'll play around with it.

3rd July 2006, 20:07
The drag and drop demo only returns a mime-type of text/uri-list regardless of what I drop into it.

Any ideas/comments?

3rd July 2006, 20:18
That's ok, look here:

here (linux, kde) there's also a text/plain format included.

3rd July 2006, 20:28
I'm getting closer. I found that uri-list basically is a description of where the dropped file is located. When using mimetypes, the member function urls will return a qlist from which I can get the individual urls of all the files. I'm using QUrl::toLocalFile(). Then I can grab the file and do what I want with it.

4th July 2006, 10:56
If you drag a file from your desktop or file manager, you'll always get the uri-list mime, regardless of the file type. If you want to get the file as application/pdf, the application you drag from has to offer the file in pdf format (meaning that it has to be able to read and maybe also write pdf files) -- like pdf readers. For example my pdf viewer (Kpdf) doesn't support dragging, so it can't offer application/pdf.