[PyKDE] Re: [PyKDE]PYKDE Drag and drop

Jim Bublitz jbublitz at nwinternet.com
Mon Jun 19 18:53:07 BST 2000


I figured it out and it *was* my mistake.

The QListView widget does not manage it's space
directly - it does it through a QWidget it owns
(actually QScrollView owns) which is held in the 
variable viewport (part of a structure) and 
accessed through self.viewport ().

To get the Drag/Drop events to operate, you need
to create a subclass of QDropSite (as mentioned
earlier), but its parent needs to be 
self.viewport () (where self is the QListView).
In the subclassed QDropSite, you need to 
override each of the Drag/Drop events, for
example:

class myDropSite (QDropSite):
   def __init__(self, parent):
      QDropSite.__init__(self, parent)
      self.parent = parent

   def dragMoveEvent (self, e):
      return self.parent.parent().dragMoveEvent (e)

...

class myListView (QListView):
...
	self.dropSite = myDropSite(self.viewport())

   def dragMoveEvent (self, e):

...

since you can't directly add/override event 
handlers in self.viewport. The viewport
part is documented on the QScrollView page
in the Qt docs.

Apparently viewport, not QListView gets the mouse 
events through event(), too, so the QDragObject 
(or QTextObject, etc) should probably be parented
on viewport, since it installs event filters 
which are activted from event () (I'm dragging 
from a QListView to another QListView). I haven't 
tried this yet, but expect it will work.

Jim





More information about the PyQt mailing list