Results 1 to 2 of 2

Thread: PyQt->QTreeWidget to QGraphicsView drop failure

  1. #1
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default PyQt->QTreeWidget to QGraphicsView drop failure

    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

  2. #2
    Ondertitel Guest

    Default Re: PyQt->QTreeWidget to QGraphicsView drop failure

    Still not answered after almost two years?
    For other Googlers like me reaching this thread, you have to implement this too:
    Qt Code:
    1. def dragMoveEvent(self, event):
    To copy to clipboard, switch view to plain text mode 

    The most confusing moment was when you want to drop on "normal" widget you need to reimplement dropEvent and dragEnterEvent, but when you drop on QGraphcisView, you need to reimplement dragMoveEvent too.
    source

Similar Threads

  1. Drag and Drop from QListView to QGraphicsView
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 20th August 2009, 14:26
  2. Replies: 1
    Last Post: 8th January 2009, 17:40
  3. Drar and Drop on QGraphicsView
    By rippa in forum Qt Programming
    Replies: 8
    Last Post: 19th November 2008, 17:02
  4. Drag and drop from QTreeWidget to QGraphicsView
    By igu@na in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2008, 08:24
  5. Speed, transparency, and drop issues with QGraphicsView
    By jefferai in forum Qt Programming
    Replies: 16
    Last Post: 30th June 2007, 16:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.