[PyKDE] Drag-Drop Doom
Torsten Marek
shlomme at gmx.net
Tue Jul 29 11:51:01 BST 2003
Vio schrieb:
> 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 ----------------------------------
>
>
One of the traps of using dNd with QIconView/QListView is that you need
to call self.viewPort().setAcceptDrops(True). Maybe that does it for you.
greetings
Torsten
--
Torsten Marek <shlomme at gmx.net>
ID: A244C858 -- fingerprint 1902 0002 5DFC 856B F146 894C 7CC5 451E
A244 C858
www.keyserver.net -- wwwkeys.eu.pgp.net
< information must flow >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 252 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030729/4c5f65bd/attachment.bin
More information about the PyQt
mailing list