PyQt: Pulling Abstract Item Data from Mime Data using Drag and Drop.

Discussion in 'Python' started by Mudcat, Dec 12, 2008.

  1. Mudcat

    Mudcat Guest

    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. Does anyone
    know how to convert/retrieve the information into a Python list?

    Thanks
    Mudcat, Dec 12, 2008
    #1
    1. Advertising

  2. Mudcat

    David Boddie Guest

    On Friday 12 December 2008 02:05, Mudcat wrote:

    > 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".


    That's correct, retrieveData() is a protected function in C++ and the
    QMimeData object was created by the framework, not you, in this case.

    > Obviously I am not retrieving them in the correct format. Does anyone
    > know how to convert/retrieve the information into a Python list?


    You could use the data() method to get the serialized data then try to
    extract the list item-by-item using the QDataStream class, or perhaps
    PyQt has a convenience function to unpack the items.

    Alternatively - and this is a bit speculative - perhaps you can copy
    the data to another QMimeData object which you have created, and use
    its retrieveData() method to retrieve the items.

    You might get a more detailed response by asking on the PyQt mailing list:

    http://www.riverbankcomputing.com/mailman/listinfo/pyqt

    Hope this helps,

    David
    David Boddie, Dec 13, 2008
    #2
    1. Advertising

  3. Mudcat

    Mudcat Guest

    Re: PyQt: Pulling Abstract Item Data from Mime Data using Drag andDrop.

    On Dec 12, 6:17 pm, David Boddie <> wrote:
    > That's correct, retrieveData() is a protected function in C++ and the
    > QMimeData object was created by the framework, not you, in this case.


    Ah, well that explains it. Figured as much but was hoping maybe I was
    trying to access it incorrectly.


    > You could use the data() method to get the serialized data then try to
    > extract the list item-by-item using the QDataStream class, or perhaps
    > PyQt has a convenience function to unpack the items.


    I tried to get info back using data() but kept getting null values.
    Same goes for the items() function which is fed with mimeData and is
    supposed to return a list. From the documentation it appeared that was
    supposed to be the middle-man to re-convert the data. I know the data
    existed because I could drag/drop elements from one treeWidget to
    another but still couldn't get data back from the target widget.


    > Alternatively - and this is a bit speculative - perhaps you can copy
    > the data to another QMimeData object which you have created, and use
    > its retrieveData() method to retrieve the items.


    I started down the path of creating my own MimeType but then realized
    it was quicker to just override the drop() function and grab the
    selected items from the source widget, just letting the mime data
    disappear into the ether. A little klugey but deadline is fast
    approaching. However I'll give the pyqt mailing list a shot. I didn't
    know there was one just for pyqt.

    Thanks for all the help,
    Marc
    Mudcat, Dec 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oliver Klein
    Replies:
    0
    Views:
    685
    Oliver Klein
    Aug 24, 2003
  2. CJ
    Replies:
    1
    Views:
    1,564
    Andrew Thompson
    Oct 29, 2004
  3. Stefan Ram
    Replies:
    27
    Views:
    728
    Stefan Ram
    Aug 17, 2009
  4. Jan Arickx
    Replies:
    0
    Views:
    192
    Jan Arickx
    Aug 25, 2003
  5. ecureuil
    Replies:
    0
    Views:
    320
    ecureuil
    May 28, 2006
Loading...

Share This Page