[Interest] QListView: drag&drop custom item

André Somers andre at familiesomers.nl
Thu Aug 18 07:33:02 CEST 2016



Op 16/08/2016 om 09:26 schreef Frank Rueter | OHUfx:
> Hi,
>
> I am trying to get drag&drop to work between two QListViews using a 
> custom item.
> I can't find the info I need online other than this document 
> <https://doc.qt.io/archives/4.6/model-view-dnd.html> which helped a 
> little bit but now I'm stuck.
>
> Drag&drop from one QListView to another works fine when I use a 
> QStandardItem to hold my data, but when I use a custom item I run into 
> trouble, because the receiving model/view creates a QStandardItem when 
> the incoming custom items are dropped.
>
> Ideally I could tell the receiving model to use my custom item as the 
> default item and otherwise just do it's thing, but I suppose it won't 
> be that easy?!
> I have played around with the receiving model's dropMimeData() and 
> insertRows() methods but can't work out how to read the incoming data 
> to then insert a custom item into the receiving model manually.
> In QAbstractItemModel.dropMimeData() I tried reading 
> mimeData.data('application/x-qabstractitemmodeldatalist'), but that 
> returns a byte stream that I don't know how to handle.
>
> Do I have to re-implement the sender's drag data as well to send the 
> custom item in the first place?
>
> It seems that everything works out of the box except the creation of 
> the QStandardItem upon drop, rather than my custom item, so I am 
> hoping I don't have to re-invent the (drag&drop) wheel just to get 
> that one part right?!
>
> Any advise would be greatly appreciated.
>
> Thanks,
> frank
>

What kind of models are you using behind these views? Custom models or 
QStandardItemModel instances? To me, it sounds like the latter?

André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160818/3adf51ee/attachment.html>


More information about the Interest mailing list