[PyKDE] D'nD problem

Thierry Jouve jouve at esrf.fr
Tue Jul 2 15:03:00 BST 2002


Hi,

I have a problem with drag'n drop...

I want to drag and drop only a string between two widgets. It's quite
simple to realise, but it doesn't work...

For example :

#!/usr/bin/env python

from qt import *

class IconViewSource(QIconView):
 
   def __init__(self, parent = None, name = None) :
      QIconView.__init__(self, parent, name)

   def dragObject(self) :
      print "iv1.dragObject"

      item = self.currentItem()
      if (not item) :
         return

      return QTextDrag(str(item.text()), self)

  
class IconViewTarget(QIconView):
 
   def __init__(self, parent = None, name = None) :
      QIconView.__init__(self, parent, name)
      self.setAcceptDrops(1)

   def dragEnterEvent(self, event) :
      print "   iv2.gragEnterEvent"

      event.accept(1)

   def dropEvent(self, event) :
      print "      >>> iv2.dropEvent"

      print "dropEvent"


import sys
qa = QApplication(sys.argv)

f = QFrame()
f.show()
layout = QHBoxLayout(f)

ivSource = IconViewSource(f)
ivTarget = IconViewTarget(f)
ivSource.show()
ivTarget.show()

ivi1 = QIconViewItem(ivSource, "item11")
ivi2 = QIconViewItem(ivSource, "item12")
ivi3 = QIconViewItem(ivSource, "item13")
ivi1.setDragEnabled(1)
ivi2.setDragEnabled(1)
ivi3.setDragEnabled(1)

layout.addWidget(ivSource)
layout.addWidget(ivTarget)

qa.setMainWidget(f)
qa.exec_loop()



With this script, all is good, except that "dropEvent" method is not
called in the target widget when user released the mouse button... And I
don't know why !!

Another thing : dragEnterEvent is not called everytime.... If user move
the mouse a little bit fast, the method is not called....

I have search in Qt doc, in PyQt doc, and I have not found anything

Python : 2.1.1
Qt :3.0.2
PyQt : 3.2.4
Linux : 2.4.7

--
   Thierry JOUVE

   BLISS GROUP - ESRF
   Mail : jouve at esrf.fr, Office : 155b, Tel : 29-46




More information about the PyQt mailing list