Results 1 to 3 of 3

Thread: Getting AbstractItemData from drag/drop in Python

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Default Getting AbstractItemData from drag/drop in Python

    I'm trying to drag/drop info from a TreeWidget into a TextBox. I have been able to modify the TextEdit box to override the dragEnterEvent like this:

    class TextEdit(QtGui.QTextEdit):
    def __init__(self, title, parent):
    QtGui.QTextEdit.__init__(self, title, parent)
    self.setAcceptDrops(True)

    def dragEnterEvent(self, event):
    if event.mimeData().hasFormat('text/plain'):
    event.accept()
    elif (event.mimeData().hasFormat("application/x-qabstractitemmodeldatalist")):
    print event
    itemData = event.mimeData().retrieveData("application/x-qabstractitemmodeldatalist", QtCore.QVariant.List)


    The drag is working up until the point I try to actually retrieve the data. At that point I get an unhandled Runtime Error saying "no access to protected functions or signals for objects not created in Python". Obviously I am not retrieving them in the correct format. How do I do that?

    Thanks

  2. #2
    Join Date
    Dec 2008
    Posts
    13

    Default Re: Getting AbstractItemData from drag/drop in Python

    Anyone? I've tried to cast it into something else and modify the data before-hand, either way I can't get the data out once it gets packed into the MIME format.

    I've seen a couple of other places where this was done before in PyQt3. Is this just something that doesn't work in PyQt4.

  3. #3
    Join Date
    Dec 2008
    Posts
    13

    Default Re: Getting AbstractItemData from drag/drop in Python

    One other aspect that doesn't make sense is that if I pass the mimeData directly into the items() function it should translate the data and give back a list:

    class ListBoxDnD(QListWidget):
    def __init__(self, parent):
    QListWidget.__init__(self, parent)
    self.setDragEnabled(True)
    self.setAcceptDrops(True)
    ...

    def dropEvent(self, e):
    print self.items(e.mimeData())

    However, even though I see the data passed into the 2nd treeWidget (so I know the data is there) this function returns an empy set []. I should at least be getting data back from this function.

    The only work-around I've found so far is to simply override the drop and go grab the selected items from the original tree. I guess that will work, but I'd like to know why this other stuff isn't working.

Similar Threads

  1. Qt, Python and pop-ups
    By bashamehboob in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2007, 20:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.