PDA

View Full Version : Drop items onto explorer.exe



louis_xx
20th May 2008, 23:32
Dear all, I would love to hear from someone who has got dropping items from a view onto explorer. I wish to drag items out of my tree view and have them become files. (.txt)

This article seems to provide useful details.
http://www.codeproject.com/KB/shell/explorerdragdrop.aspx


I have looked into the way windows does this and from what I understand, i need to create a COleDataSource. Constructing the data to pass to the source is a bit involved but ok.. then call DoDragDrop on the DataSource and your home and dry.

Qt seems to have or fake something that can recieve windows drops, but does anyone have experience of dropping stuff from qt? I.e. how would I write a qt app that can use a COleDataSource?

aamer4yu
21st May 2008, 07:34
I guess u will need to look at the formats of the mimedata for drag and drop.
You need to see what mimedata explorer accepts / processes and then set ur mimedata for drag acccordingly.

louis_xx
21st May 2008, 11:56
As far as I have understood windows doesn't accept mime data drops. So you have to do it the windows way. I am up for having a crack at creating the data. Where I would love some help is in using the required Microsoft classes in my QT app. I am guessing that I will need to download the windows sdk. But this is uncharted territory for me and I would love to hear from someone who has used, or linked to microsoft code in a QT app.

jpn
22nd May 2008, 21:49
You just have to dump the contents to a temp file. Here's a dummy example:


#include <QtGui>

class Label : public QLabel
{
protected:
void mouseMoveEvent(QMouseEvent* event)
{
QTemporaryFile file;
if (file.open())
{
QUrl url = QUrl::fromLocalFile(file.fileName());
file.write(text().toUtf8());
file.close();

QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
mimeData->setUrls(QList<QUrl>() << url);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
}
};

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Label label;
label.setText("foo bar");
label.show();
return app.exec();
}

coolboy123
4th December 2008, 08:13
Thanks, it's what I am longing for...


You just have to dump the contents to a temp file. Here's a dummy example:


#include <QtGui>

class Label : public QLabel
{
protected:
void mouseMoveEvent(QMouseEvent* event)
{
QTemporaryFile file;
if (file.open())
{
QUrl url = QUrl::fromLocalFile(file.fileName());
file.write(text().toUtf8());
file.close();

QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
mimeData->setUrls(QList<QUrl>() << url);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
}
};

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
Label label;
label.setText("foo bar");
label.show();
return app.exec();
}