Hi,

Task:
Drag item from QTreeWidget and drop it to QGraphicsView

Here is the property set up and function to start the drag in QTreeWidget.
I am not using any more function except this one:
Qt Code:
  1. ....
  2. #
  3. self.setDragEnabled(True)
  4. self.setHeaderHidden(True)
  5. self.setColumnCount(1)
  6. self.setFocusPolicy(QtCore.Qt.NoFocus)
  7.  
  8. def startDrag(self, supportedActions):
  9.  
  10. print self.currentItem().text(0)
  11. currentItemName = self.currentItem().text(0)
  12.  
  13. mimeData = QtCore.QMimeData()
  14. mimeData.setText(currentItemName)
  15.  
  16. drag = QtGui.QDrag(self)
  17. drag.setMimeData(mimeData)
  18.  
  19. dropAction = drag.start(QtCore.Qt.CopyAction)
To copy to clipboard, switch view to plain text mode 

Here is the property set up and function for dropping in QGraphicsView.
I am using only two functions here:
Qt Code:
  1. ....
  2. self.setScene(QxScene(self))
  3. self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
  4. self.setRenderHint(QtGui.QPainter.Antialiasing, 1)
  5. self.setDragMode(QtGui.QGraphicsView.RubberBandDrag)
  6. self.setOptimizationFlags(QtGui.QGraphicsView.DontSavePainterState)
  7. self.setViewportUpdateMode(QtGui.QGraphicsView.SmartViewportUpdate)
  8. self.setBackgroundBrush(QtCore.Qt.lightGray)
  9. self.setAcceptDrops(True)
  10.  
  11. def dragEnterEvent(self, event):
  12. if event.mimeData().hasText():
  13. event.acceptProposedAction()
  14. print "enter accepted"
  15. else:
  16. print "enter ignore"
  17. event.ignore()
  18.  
  19. def dropEvent(self, event):
  20. if event.mimeData().hasText():
  21. xmlFileName = event.mimeData().text()
  22. position = event.pos()
  23. event.setDropAction(QtCore.Qt.CopyAction)
  24. event.accept()
  25. print xmlFileName, position
  26. else:
  27. print "drop ignore"
  28. event.ignore()
To copy to clipboard, switch view to plain text mode 

As soon as mouse is entering in QGraphicsView, message "event accepted" is getting printed in function "dragEnterEvent".

Problem is that cursor is still forbidden cursor and I can't drop.


Cheers

Prashant

Python 2.5.2
PyQt-Py2.5-gpl-4.4.3-1
Win XP, 32 Bit