[PyKDE] Drag-Drop Doom

Vio vmilitaru at sympatico.ca
Tue Jul 29 10:16:01 BST 2003


Greetings,
I am trying to implement D&D. 
Dragging seems to work, but my code ain't "dropping" it.
Could someone "drag" their eyeballs over my code and maybe "drop" me some hints...

Ok, what I want to do is simple: I have 2 or more instances of 
"my_QIconView", populate them with some icons, 
and then I want to "D&D" icons between them.
Incidently, D&D inside the same my_QIconView works (don't ask me why:).
Just not between side-by-side my_QIconView instances.

In my opinion, the problem resides somewhere in "contentsDropEvent()", but then
I don't quite understand the C++ examples 'dragdrop' nor 'fileiconview'.
Couldn't find much on D&D in the list's archive either.

Cheers,
Vio


--- start code segment ----------------------------------

class my_QIconView(QIconView):
	"testing Drag&drop"
	def __init__(self,dragSource = None,name = None): 
		QIconView.__init__(self, dragSource, name)
		self.setAcceptDrops(TRUE)

# DRAG ----------

	def startDrag(self):
		"Drag-drop functionality"
		print self.parent().name(),'---startDrag---'
		d = self.dragObject() # get appropriate drag object
		print self.parent().name(),'d1>',d
#		d.drag(QIconDrag.DragCopyOrMove) - bad call: runtime error
		d.dragMove()
#		d.dragCopy() # calls dragEnterEvent,dragMoveEvent,dragLeaveEvent
			 # when 'drag' cursor leaves widget's boundaries
		print self.parent().name(),'d2>',d

	def dragEnterEvent(self, e):
		print self.parent().name(),'---dragEnterEvent---',e.format()
		print 'canDecode>',e.accept(QIconDrag.canDecode(e))

	def dragMoveEvent(self, e):
		print self.parent().name(),'---dragMoveEvent---',e.pos()
		if e.source():
			e.acceptAction()

	def dragLeaveEvent(self, e):
		print self.parent().name(),'---dragLeaveEvent---',e

# DROP ---------------

	def contentsDropEvent(self, e):
		print self.parent().name(),'---contentsDropEvent---'
		print self.parent().name(),e.encodedData(e.format())
		print 'e>',e
		print 'action>',e.action()
		
		if e.action() == QDropEvent.Move:
			print 'contentsDropEvent> MOVE'
		elif e.action() == QDropEvent.Copy:
			print 'contentsDropEvent> COPY'

		""" BAD code following up: yes, how do I get at my icon from here?

		icon = QPixmap()
		if QIconDrag.canDecode(e, icon):
			self.insertItemAt(icon, e.pos())
		"""
--- end code segment ----------------------------------







More information about the PyQt mailing list