[Qt-interest] Drag and Drop Pointers/QModelIndex Within Application
Robert Hairgrove
evorgriahr at hispeed.ch
Mon May 25 12:25:52 CEST 2009
Karol Krizka wrote:
> Hi there,
>
> I'm basically trying to add a DnD interface to my application. I do not
> need to be able to drag/drop outside of the application.
>
> I basically have a list of categories, each with a set of items
> organizes in a tree (QTreeView). I want to be able to move the items
> between the categories by dragging and dropping them. I thought the best
> idea would be to pass the QModelIndex of the items being dragged in the
> DnD event and then in the dropAction, I would figure out where the index
> came from and where it was dropped, then perform the move. Another idea
> was that I pass the pointer to the item.
>
> However, the data for a DnD event seems to be passed via the QMimeData
> structure, which only supports data in the format of color, string, html
> or a bytestream.
>
> So, what is the best way to pass data using DnD inside an application?
>
> --
> Cheers,
> Karol Krizka
> http://www.krizka.net
You can register your own class as a new mime data type, but you must
implement the streaming operators for it (i.e., << and >>). It is very
easy to do, though.
Open QtAssistant and read the "Drag and Drop" overview as well as the
description of the QMimeData and QDropEvent classes. There are many
examples there.
More information about the Qt-interest-old
mailing list