[Interest] QListView: drag&drop custom item
Viktor Engelmann
viktor.engelmann at qt.io
Wed Aug 17 10:24:31 CEST 2016
The QStandardItem seems to be used to limit the drag&drop to files,
images, text etc. so that you can drag & drop from and to external
applications (which is not possible for general objects).
http://doc.qt.io/qt-4.8/qstandarditem.html#subclassing says you should
subclass QStandardItem and override read and write or data and setData.
That is probably used to marshal and unmashal the objects, to make them
compatible to text, which can be passed to and from external applications.
Viktor
On 16.08.2016 23:56, Frank Rueter | OHUfx wrote:
> Anybody?
> I can find plenty of examples on how to drag items from a view to a
> widget but can't find anything about dragging a custom item from one
> view to another.
> Guess I will start to re-implement the entire drag&drop, maybe the
> solution will become apparent then.
>
>
> On 16/08/16 7:26 PM, Frank Rueter | OHUfx wrote:
>> 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
>>
>>
>>
>> --
>> ohufxLogo 50x50 <http://www.ohufx.com> *vfx compositing
>> <http://ohufx.com/index.php/vfx-compositing> | *workflow
>> customisation and consulting
>> <http://ohufx.com/index.php/vfx-customising>* *
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
--
Viktor Engelmann
Software Engineer
The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
Viktor.Engelmann at qt.io
+49 151 26784521
http://qt.io
Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
<http://qt.io>
<http://www.facebook.com/Qt> <http://www.twitter.com/qtproject>
<https://www.linkedin.com/company/the-qt-company/>
<https://plus.google.com/104580575722059274792>
<https://www.youtube.com/QtStudios>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_logo_with_text_green_rgb_400x141.png
Type: image/png
Size: 16849 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_facebook.png
Type: image/png
Size: 1407 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_twitter.png
Type: image/png
Size: 1778 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_linkedin.png
Type: image/png
Size: 1532 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_googleplus.png
Type: image/png
Size: 1957 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_youtube.png
Type: image/png
Size: 1610 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viktor_engelmann.vcf
Type: text/x-vcard
Size: 271 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160817/92f1fb33/attachment.vcf>
More information about the Interest
mailing list