You just have to dump the contents to a temp file. Here's a dummy example:
#include <QtGui>
{
protected:
{
if (file.open())
{
QUrl url
= QUrl::fromLocalFile(file.
fileName());
file.write(text().toUtf8());
file.close();
mimeData->setUrls(QList<QUrl>() << url);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
}
};
int main(int argc, char* argv[])
{
Label label;
label.setText("foo bar");
label.show();
return app.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks