Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > PyQt: Pulling Abstract Item Data from Mime Data using Drag and Drop.

Reply
Thread Tools

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

 
 
Mudcat
Guest
Posts: n/a
 
      12-12-2008
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
 
Reply With Quote
 
 
 
 
David Boddie
Guest
Posts: n/a
 
      12-13-2008
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
 
Reply With Quote
 
 
 
 
Mudcat
Guest
Posts: n/a
 
      12-14-2008
On Dec 12, 6:17*pm, David Boddie <(E-Mail Removed)> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using "abstract" on a class with no abstract method Stefan Ram Java 27 08-17-2009 12:36 AM
Problem with Email::MIME and Email::MIME::Attachment::Stripper ecureuil Perl Misc 0 05-28-2006 01:47 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
how 2 convert mime to txt or extract words from mime joe Perl Misc 0 04-07-2004 12:34 AM
Receiving zip files via Mime::Parser/Mime::Decoder Jan Arickx Perl Misc 0 08-25-2003 08:24 PM



Advertisments