[PyKDE] File Drag n drop

Matt Newell newellm at blur.com
Wed Jan 10 19:59:42 GMT 2007


On Tuesday 09 January 2007 16:57, Tony Cappellini wrote:
> After looking through the examples & demos,  I don't see an example of what
> I'm looking for.
>
> I would like to be able to drag a file or files onto a Python QT app, and
> have the app process the file(s).
>
> The Draggable Icons example isn't quite the same. I want to drag a file
> from outside of the application, onto the running application.
>
> Does anyone know where I can find an example to do this?
>
> thanks


from PyQt4.QtGui import *
import sys

class DropLabel(QLabel):
	def __init__(self,parent=None):
		QWidget.__init__(self,parent)
		self.setAcceptDrops(True)
		self.setText( "Drop Files or Urls Here" )
		self.resize(self.sizeHint())
		
	def dragEnterEvent(self,event):
		if event.mimeData().hasUrls():
			event.acceptProposedAction()

	def dropEvent(self,event):
		self.setText('\n'.join([str(url.toString()) for url in 
event.mimeData().urls()]))
		self.resize(self.sizeHint())

app = QApplication(sys.argv)

w = DropLabel()
w.show()

app.exec_()



Matt




More information about the PyQt mailing list