PDA

View Full Version : Drag&Drop - Pointer into QMimeData?



droetker
10th October 2009, 22:59
Hi,
I'm new to Qt - it's really cute, but I don't fully understand how drag/drop is really working. I've done some tutorials already, but neither they nor google could answer my question.
I have a two QTreeWidgets with custom Items; and I want Qt to do the following:
If the user drags an Item from Widget A to Widget B, it gets "linked" to it:
I create a new special Item in B, and want to have a "pointer" property that points to the original item in A.
QMimeData can only handle Text, URLs etc, but no pointers.
How do I do that? Do I have to subclass QMimeData just for doing that?

Can I somehow "link" an Item from QTreeWidget A to QTreeWidget B without copying it? (I think not)

How do I properly conversion between a pointer and the ByteArray QMimeData wants?

Grimlock
11th October 2009, 09:47
Have a look at Q_DECLARE_METATYPE ( Type ) and QVariant

droetker
11th October 2009, 14:14
yes, I stumbled upon thosw two as well.
I couldn't believe that I have to subclass so many classes just to provide drag&drop.

I got it working by just subclassing QMimeData and implementing another member variable with that pointer, was the easiest way - drag&drop works now as expected.

In meantime I will change the TreeWidget to a TreeView and create a proper Model underneath all of it - this seems to help me. But I thought I could get around that ;-)

in some things Qt is little straightforward. You have to define so many things yourself.
I was used to Delphi/Pascal, things are MUCH easier there.
But yes, in the end in Qt the approach is cleaner - IF you manage it...
thanky anyway,
Christian