[Qt-interest] Drag & drop mime data.

phil prentice philp.cheer at talktalk.net
Mon Mar 23 11:31:14 CET 2009


Hi
  I have a lot to learn about QT.  I have written code that allows me to drag 
data from one QLIstView to another, but I have a problem when I try and drop 
it in the second QList View.

  The first QLIstView has a model and a delegate associated with it.  The 
model simply handles strings.  The delegate handles the rendering inside the 
view (arrows, text & icons).  I am using QT Designer.  I have not promoted 
this first view to a custom widget..I am hoping to use the base classes 
functionality for drag and drop;  probably my mistake!!

  The second QLIstView I have promoted to a custom widget and have over-ridden 
the functions 
    void dropEvent(QDropEvent *event);
    void dragEnterEvent(QDragEnterEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);

  This widget also has a delegate associated with it to handle the rendering 
inside the view (again arrows, icons & text).

  When I drop the data into the second view,  dropEvent is called.  However I 
can not associate the drop event with the dragged data (strings).  Within the 
dropEvent function I have tryed things like 
QByteArray myData = 
event->mimeData()->data("application/x-qabstractitemmodeldatalist");
and
QString myData= event->mimeData()->text();

I have tryed looking at the QT-sources.. to see how the data was being 
transfered...but I am afraid they are currently beyond me (it would not be 
wise for me to try and understand them; I would just get very depressed). 

My questions really are:-
1. Can I easily get the mimed data of the first QLIstView when I drop the 
dragged item into my second promoted QListView?

2. Instead should I promote the first QLIstView and look into packing the 
mimed data  in a format that my second QLIstView will then understand? I only 
really wanted to do this if it was necessary, it looks like potentially a lot 
of work..i.e. starting from mousePressEvent() etc.

I just though that I would float this by you just in case some of you can give 
me a little direction.  Meanwhile I'm going to read in more detail the PUZZLE 
example in QT, so I have a better idea how drag & drop works for that 
example.

Any comments would be welcome

Thanks for reading this

Phil







More information about the Qt-interest-old mailing list