[PyKDE] QDropEvent.action() bug?

Matthew Bull mbull at e-healthconsultants.com
Mon Jul 28 21:39:00 BST 2003


OK there's two tricks to this (I've been working with QListView but I'm assuming it's similar)....

first after creating your drag object in dragObject() you need to set the drag type with drag.... so in my case I create a QUriDrag object then call drag() with the type of drag i want to enable (in your case DragCopyOrMove) eg.

def dragObject(self):
	dObj=qt.QUriDrag([<uri list>],self)
	dObj.drag(qt.QUriDrag.DragCopyOrMove)

second you need to set whether you are allowing a copy or move or both for the particular target so in a dragEnter or dragMove (or possibly acceptDrop I'm not sure) you need to call the acceptAction() method of the event object if you want to accept the move as well as copy events, presumably only if the dragged object is in the same application which you can check with source()... eg.

def dragMoveEvent(self,event):
	if event.source():
		event.acceptAction()
	# stuff to work out whether to accept the drop at all

then when you are dragging something you can select copy/move with the shift key...

your event.action() in your drop handler should then return the correct value depending on whether the shift key was depressed or not.

sorry for not providing a complete example but the widget I have which implements this does a whole bunch of other stuff in the drag events so wouldn't be very clear.

hope this helps and if anyone knows of an easier way of doing this (or has done it with acceptDrop()) please post it to the list.

Matt

> -----Original Message-----
> From: Phil Thompson <phil at riverbankcomputing.co.uk>
> Sent: Thu Jul 24 16:08:47 BST 2003
> To: Torsten Marek <shlomme at gmx.net>; pykde mailing list <pykde at mats.imk.fraunhofer.de>
> Cc: 
> 
> 
> There does seem to be a SIP bug because you
> shouldn't be able to create an
> instance of QDragObject as it's abstract. However
> this has nothing to do with
> your problem.
> 
> The equivalent C++ code behaves in the same way
> (using QTextDrag instead of
> QDragObject), so that implies it is an error in
> your script.
> 
> Phil
> 
> On Wednesday 23 July 2003 5:11 pm, Torsten Marek
> wrote:
> > Hi there,
> >
> > I encountered the problem that QDropEvent.action() always returns 0,
> > regardless what the drag op was started with or how. I'm using Qt 3.1.2
> > and PyQt 3.7 and it can't be a bug of Qt because in the Qt example
> > FileIconView, the application is able to distinguish between copy and
> > move event.
> > I added a small sample application demonstrating the problem (the
> > messagebox saying "the item has been copied" keeps popping up)
> >
> > --- snip here ---
> > from qt import *
> >
> > class TestListView(QListView):
> >      def __init__(self, *args):
> >          apply(QListView.__init__, (self,)+args)
> >          self.setAcceptDrops(True)
> >          self.viewport().setAcceptDrops(True)
> >          self.addColumn("first column")
> >          for i in range(1,10):
> >              item = QListViewItem(self, "item %i" % i)
> >              item.setDragEnabled(True)
> >              item.setDropEnabled(True)
> >
> >
> >      def dragObject(self):
> >          return QDragObject(self)
> >
> >      def contentsDropEvent(self, e):
> >          if e.action() == QDropEvent.Move:
> >              QMessageBox.information(self, "info", "Item has been moved")
> >          elif e.action() == QDropEvent.Copy:
> >              QMessageBox.information(self, "info", "Item has been copied")
> >
> > a = QApplication([''])
> > mw = TestListView()
> > a.setMainWidget(mw)
> > mw.show()
> > a.exec_loop()
> > --- snip here ---
> >
> > greetings
> >
> > Torsten
> 
> _______________________________________________
> PyKDE mailing list   
> PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> 


More information about the PyQt mailing list