[PyQt] Drop to system

Massimo Di Stefano massimodisasha at gmail.com
Wed Sep 8 23:29:37 BST 2010


Hi All.

i'm tring to learn a similar things ... but i can't find a solution yet :-(

i wrote a sample code from where i'm tring to start to learn how to implement a drag-ndrop action :


import sys
import os
from PyQt4 import QtCore, QtGui
from table_ui import Ui_Form


class Gui(QtGui.QWidget, Ui_Form):
	def __init__(self, parent=None):
		QtGui.QGroupBox.__init__(self, parent)
		self.setupUi(self)
		kmldir = '/Users/sasha/kml/'
		kmlfiles = self.listkml(kmldir)
		numrow = len(kmlfiles)
		self.tableWidget.setColumnCount(1)
		self.tableWidget.setRowCount(numrow)
		self.tableWidget.setEditTriggers(QtGui.QTableWidget.NoEditTriggers)
		self.connect(self.add, QtCore .SIGNAL("clicked()"), self.additem)
		for i in range(len(kmlfiles)):
			item = QtGui.QTableWidgetItem(kmlfiles[i])
			self.tableWidget.setItem(i, 0, item)
#####################################			
		self.tableWidget.setAcceptDrops(True)
		self.tableWidget.__class__.dragEnterEvent = self.DragEnterEvent
		self.tableWidget.__class__.dropEvent = self.DropEvent
		
	
	
	def DragEnterEvent(self, event):
		print "DragEnter"
		event.acceptProposedAction()
	
	
	def DropEvent(self, event):
		print "DragDrop"
		event.acceptProposedAction()
	
	
	def dragMoveEvent(self, event):
		event.acceptProposedAction()
	
#####################################
	def listkml(self,kmldir):
		dirList = os.listdir(kmldir)
		listakml = []
		for fname in dirList:
			listakml.append(fname)
		return listakml
	
	
	def additem(self):
		row = self.tableWidget.rowCount()
		newrow = row + 1
		kmldir = '/Users/sasha/kml/'
		kmlfiles = self.listkml(kmldir)
		item = QtGui.QTableWidgetItem(kmlfiles[1])
		self.tableWidget.setRowCount(newrow)
		self.tableWidget.setItem(row, 0, item)
	
		


if __name__ == "__main__":
   app = QtGui.QApplication(sys.argv)
   gui = Gui()
   gui.show()
   sys.exit(app.exec_())



the gui file is asimple widjet with one Qtable  ' self.tableWidget ' 
and one button ' self.add '


what i need is to select an item from the Qtable (it is a path to an existing file.kml) and drop it inside an external app that accept dropped file.kml 

thanks for any help!!!

Massimo.


Il giorno 08/set/2010, alle ore 23.33, Hugo Leveille ha scritto:

> I have looked at the doc but all I could find was drag and drop within the pyqt app itself. What id like to do is the, for exemple, attach an url or whatever needed to an item so that if I drag the item into my desktop, in a explorer window or whatever othe app that support drag drop, it will recongnize it
> 
> Some if anyone is nice enought to give me a quick exemple or to point me at the specific exemple where it is shown, it would be very nice



More information about the PyQt mailing list