[Qt-interest] Drag and Drop Pointers/QModelIndex Within Application
Karol Krizka
kkrizka at gmail.com
Mon May 25 13:57:54 CEST 2009
On Mon, 2009-05-25 at 12:25 +0200, Robert Hairgrove wrote:
> 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.
>
Yes, I think I will have to do that.
> 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.
I did look at those examples and the documentation. However, either of
them demonstrate what I want to do. They either pass around simple types
(ei: strings, images) or work with files outside of the application (ei:
images via QByteArray).
Thank you for your reply!
--
Cheers,
Karol Krizka
http://www.krizka.net
More information about the Qt-interest-old
mailing list