ada10
4th October 2010, 09:50
I have custom model class having a qlist of a custom metatype.
The custom metatype has a qpixmap & qstring as the member variables. Instances of this metatype are added to model data. The view which uses this model has dragEnabled(true) on its items. Hence when the items from the view are dragged, I want to send the string ( which is stored as part of the metatype ) also. How should I pass this string in the QMimeData that is passed along with the drag object ? Or is there another way to do this ?
The model's mimeData() method is -
QMimeData *pixmapmodel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
QPixmap pixmap = qVariantValue<QPixmap>(data(index, Qt::UserRole));
stream << pixmap;
}
}
mimeData->setData("image/bmp", encodedData);
return mimeData;
}
The custom metatype has a qpixmap & qstring as the member variables. Instances of this metatype are added to model data. The view which uses this model has dragEnabled(true) on its items. Hence when the items from the view are dragged, I want to send the string ( which is stored as part of the metatype ) also. How should I pass this string in the QMimeData that is passed along with the drag object ? Or is there another way to do this ?
The model's mimeData() method is -
QMimeData *pixmapmodel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
foreach (QModelIndex index, indexes) {
if (index.isValid()) {
QPixmap pixmap = qVariantValue<QPixmap>(data(index, Qt::UserRole));
stream << pixmap;
}
}
mimeData->setData("image/bmp", encodedData);
return mimeData;
}