PDA

View Full Version : drag and drop



mickey
26th May 2006, 17:45
hi, I need to implement drag and drop between to QLabel. I need if this is possible...thanks


myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name)
{
setAcceptDrops(TRUE);
}

Glitch
26th May 2006, 17:52
This is only the 1st step in many to implement drag and drop....

Check out the DND examples in QTDIR, but to give you a head up you will need to do the following...

Drag Side:
Implement mousePressEvent
Record an inital point

Implement mousePressEvent
Clear the inital point

Implement mouseMoveEvent
Compare initlaPoint to current pount. If its a reasonable distance..
Create a QDrag
Create a QMimeData (Could be text, pixmap, image, URL, HTML. Subclass for more)
Set the data on the drag
call drag->start(..)

Drop Side

In constructor
setAcceptDrops(TRUE);

Implement dragEnterEvent or dragMoveEvent
Ask the event for the mimeData and inspect the supported types
Decide if you can support the types.

Implement dragEnterEvent or dragMoveEvent
Ask the event for the mimeData
Use the data however you want.

Once you get further in this project, feel free to ask more questions.

--Justin Noel
justin@ics.com

Glitch
26th May 2006, 17:53
Oops, clear the initial point in mouseReleaseEvent....

Chicken Blood Machine
26th May 2006, 18:41
hi, I need to implement drag and drop between to QLabel. I need if this is possible...thanks


myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name)
{
setAcceptDrops(TRUE);
}

If you use two QLineEdits, you will get the drag and drop for free. You can change their colors to look like labels if necessary.

Glitch
26th May 2006, 18:50
Unless said QLabel is displaying a QPixmap or QMovie.... ;)

--Justin

georgie
27th May 2006, 04:05
there are pretty good examples for drag and drop in the docs

http://doc.trolltech.com/3.3/dnd.html

qt/examples/dragdrop